Embeed Excel Workbook

Hi

I am trying to embed an Excel Workbook into a Presentation using the Java code below. My version of Aspose Slides is 17.9.1 and Aspose Cells is 8.8.0.

public class Main {
    private static final String XLSX = "C:\\Temp\\Report.xlsx";
    private static final String PPTX = "C:\\Temp\\Report.pptx";

    public static void main(String[] args) {
        try {

            // Create the workbook
            System.out.println("Creating workbook ...");
            Workbook book = new Workbook();
            WorksheetCollection sheets = book.getWorksheets();
            for (int index = 0; index < 10; index++) {
                if (index > sheets.getCount() - 1) {
                    sheets.add();
                }
                Worksheet sheet = sheets.get(index);
                String name = "Sheet " + String.valueOf(index + 1);
                sheet.setName(name);
                Cells cells = sheet.getCells();
                for (int row = 0; row < 10; row++) {
                    cells.get(row, 0).setValue(name + "," + String.valueOf(row + 1));
                }
            }
            System.out.println("Saving workbook to \"" + XLSX + "\" ...");
            book.save(XLSX, com.aspose.cells.SaveFormat.XLSX);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            book.save(stream, com.aspose.cells.SaveFormat.XLSX);
            stream.close();

            // Create the presentation and embed the workbook
            System.out.println("Creating presentation ...");
            Presentation pres = new Presentation();
            ISlide sld = pres.getSlides().get_Item(0);
            Dimension2D size = pres.getSlideSize().getSize();
            IOleObjectFrame oof = sld.getShapes().addOleObjectFrame(0, 0, (int)size.getWidth(), (int)size.getHeight(), "Excel.Sheet.12", stream.toByteArray());
            System.out.println("Saving presentation to \"" + PPTX + "\" ...");
            pres.save(PPTX, com.aspose.slides.SaveFormat.Pptx);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

The result I get is a PowerPoint presentation that shows the text “EMBEDDED OLE OBJECT” where I expected a preview of my Excel workbook. I attached the resulting presentation (ZIPPED).

Report.zip (38.7 KB)

Is there another way of embedding an Excel Workbook? Did I forget to do something?

All the best

Patrick

@Paddynski,

I have observed the requirements shared by you and like to share that whenever you add an ole object frame to slide, it gets added in disabled form. The red message show “Embedded Object” highlights that Ole object has been added but it is in not activated. This is neither an issue with Aspose.Slides nor an issue with PowerPoint. One need to active the Ole frame to show the Ole object content. There are two approaches that one can use in this regard.

First is that you create MS Excel Chart image and set that as OLE Object Frame image to avoid red “EMBEDDED OLE OBJECT”. You need Aspose.Cells for this to get the chart image and set that as OLE Object Frame image. Please visit documentation article, Creating Excel Chart and Embedding it in Presentation as OLE Object for your reference, whereby you will observe the code sample for generating worksheet image and setting that as OLE frame image.

Another solution to avoid default red, “EMBEDDED OLE OBJECT” image for added OLE Object Frame is to use any third party macros which could enable the OLE Object Frames in your presentation as soon as that is opened in PowerPoint. This way whenever the presentation will be loaded, all the OLE Object Frames will get enabled and will display the actual data view.