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