@sukritisehgal,
Unfortunately, I can’t determine the cause of the error you encountered. We are sorry that you encountered this problem. Please send the files to andrey.potapov@aspose.com
.
@sukritisehgal,
We have opened the following new ticket(s) in our internal issue tracking system and will address the issues according to the terms outlined at Free Support Policies.
Issue ID(s): SLIDESJAVA-39662
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks, please let me know if there is any solution on this.
@sukritisehgal,
Our developers have reviewed your requirements.
Please try using the following code example:
String excelFileName = "linked_excel.xlsx";
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
Workbook workbook = new Workbook(excelFileName);
Range cellRange = workbook.getWorksheets().get("sheet1").getCells().createRange("G2:M12");
IOleObjectFrame frame = slide.getShapes().addOleObjectFrame(20, 300, 400, 200, "Excel.Sheet.12", excelFileName);
frame.setLinkPathLong(frame.getLinkPathLong() + getAddressOnWorksheet(cellRange));
frame.getSubstitutePictureFormat().getPicture().getImage().replaceImage(createOleImage(cellRange));
frame.setUpdateAutomatic(false);
cellRange = workbook.getWorksheets().get("sheet1").getCells().createRange("C2:E23");
frame = slide.getShapes().addOleObjectFrame(420, 20, 200, 100, "Excel.Sheet.12", excelFileName);
frame.setLinkPathLong(frame.getLinkPathLong() + getAddressOnWorksheet(cellRange));
frame.getSubstitutePictureFormat().getPicture().getImage().replaceImage(createOleImage(cellRange));
frame.setUpdateAutomatic(false);
cellRange = workbook.getWorksheets().get("sheet1").getCells().createRange("G18:J22");
frame = slide.getShapes().addOleObjectFrame(20, 20, 200, 70, "Excel.Sheet.12", excelFileName);
frame.setLinkPathLong(frame.getLinkPathLong() + getAddressOnWorksheet(cellRange));
frame.getSubstitutePictureFormat().getPicture().getImage().replaceImage(createOleImage(cellRange));
frame.setUpdateAutomatic(false);
cellRange = workbook.getWorksheets().get("sheet1").getCells().createRange("C26:E31");
frame = slide.getShapes().addOleObjectFrame(420, 300, 200, 70, "Excel.Sheet.12", excelFileName);
frame.setLinkPathLong(frame.getLinkPathLong() + getAddressOnWorksheet(cellRange));
frame.getSubstitutePictureFormat().getPicture().getImage().replaceImage(createOleImage(cellRange));
frame.setUpdateAutomatic(false);
presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();
static String getAddressOnWorksheet(Range cellRange)
{
String worksheetName = "sheet1";
return "!"+worksheetName+"!R"+(cellRange.getFirstRow() + 1)+ "C" + (cellRange.getFirstColumn() + 1) +
":R"+(cellRange.getFirstRow() + cellRange.getRowCount())+"C" + (cellRange.getColumnCount() + cellRange.getFirstColumn());
}
static byte[] createOleImage(com.aspose.cells.Range cellRange) throws Exception
{
PageSetup pageSetup = cellRange.getWorksheet().getPageSetup();
pageSetup.setPrintArea(cellRange.getAddress());
pageSetup.setLeftMargin(0);
pageSetup.setRightMargin(0);
pageSetup.setTopMargin(0);
pageSetup.setBottomMargin(0);
pageSetup.clearHeaderFooter();
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setOnePagePerSheet(true);
imageOrPrintOptions.setOnlyArea(true);
imageOrPrintOptions.setImageType(com.aspose.cells.ImageType.EMF);
SheetRender sheetRender = new SheetRender(cellRange.getWorksheet(),
imageOrPrintOptions);
sheetRender.toImage(0, imageStream);
return imageStream.toByteArray();
}
However, we want to point out that the issue with the OLE shape size changing when updating links is still present. Unfortunately, there is nothing we can do on our end at this time, as this is an OLE object linking issue between PowerPoint and Excel.
Manage OLE|Aspose.Slides Documentation
Object Preview Issue when Adding OleObjectFrame|Aspose.Slides Documentation
Hi Andrey
Thanks for sharing the code.
I tried this approach but the tables and text on the presentation are images, not OLE objects.
We need on the data on the presentation to change when the excel changes.
I am able to do this with a single table using :
slide.shapes.add_ole_object_frame(
50, 50, 500, 300, # x, y, width, height
"Excel.Sheet.12", # ProgID for Excel
excel_file_path # Path to the linked Excel file
)
But this approach only works when the table starts at cell A1 of the Excel file.
We will also prefer embedded(not linked) excels for all the tables and text with OLE objects on the presentation. Incase embedded is not an option, we can also work with a linked excel.
Thanks
Sukriti
When you manually add an OLE object to a PowerPoint presentation, an image of the object is automatically created and displayed on the slide (provided that the icon option is not selected for the object). Aspose.Slides offers the same capability.
The code example above demonstrates how to specify the cell range for the OLE object data.
This article shows how to add OLE objects with embedded Excel files.
Please let us know if you have any difficulties with this, and describe the issue in greater detail.
Hi Andrey,
I understand. This is exactly what I am looking to do programmatically. But the code you shared above, adds the tables as images not OLE objects.
To clarify, if I add an OLE object in PowerPoint, you are correct that it creates and displays an image of the object. But if I change the underlying Excel data, the image gets refreshed.
This refreshing capability is not working in the code you have shared above. The images on the presentation are static images.
Yes, I am following the same approach. This lets me create an embedded excel for the OLE objects. But it shows the entire excel sheet as an image instead of just 1 table, G2: M12. I tried using the createRange function similar to your code, but it is still displaying the entire excel sheet.
Can you please help to share another code example, that adds the OLE objects to the PPT with a refresh capability. Similar to pasting using Ctrl + Alt+ V manually → paste Link manually.
The requirement is that even though it is an image it should refresh when the underlying data changes.
Happy to get on a call to discuss this further.
This is very important for us.
@sukritisehgal,
We provide free support exclusively on this forum. We apologize for any inconvenience caused. I need some time to check the issue. I will get back to you as soon as possible.
Hi Andrey
I have been working with this as well, I realized if I right click on the image(after using the code you shared) and click on Update Link it actually refreshes the image.
So this is a viable solution for us, thank you.
I am good with the linking(instead of embedding) as long as I can link all objects using the OLE approach - charts, tables and text
Can you also please share some code embedding charts as OLE objects and linking(not embedding) them to an excel file. I have a chart in the ppt and excel file I shared with you on email, so you can use that as an example.
To clarify the problem statement, given a chart and data in Excel.
Add the chart as an OLE object in PowerPoint, such that PowerPoint shows the image of the chart, but double clicking the chart opens the Excel file. emulating the Ctrl + Alt + V behavior manually.
This is my code to accomplish this, but it renders the entire Excel as an image on the PPt instead of just the chart.
sheet_name = "Apple, Inc."
chart_index = 0 # Index of the chart in the worksheet
chart = workbook.worksheets.get(sheet_name).charts[chart_index]
img_stream = io.BytesIO()
chart.to_image(img_stream, ImageType.PNG)
img_stream.seek(0)
img = presentation.images.add_image(img_stream)
frame = slide.shapes.add_ole_object_frame(
20, 100, 144, 144,
"Excel.Sheet.12",
excel_file_name
)
frame.substitute_picture_format.picture.image.replace_image(img)
frame.update_automatic = True
@sukritisehgal,
Thank you for the code example. I’ll need a little time to investigate the issue and will get back to you promptly.
@sukritisehgal,
Thank you for your patience. I was trying to meet your requirements. It appears that PowerPoint does not provide such a feature, so Aspose.Slides cannot offer it either. If I have misunderstood anything, please provide step‑by‑step instructions on how to accomplish your goal manually in PowerPoint, and we will then help you do the same with Aspose.Slides. If you can perform this manually in PowerPoint, we can provide the corresponding code to achieve the same.
Hey Andrey,
Here is how I do it manually in Excel and PowerPoint,
- Assuming I have an Excel with a Chart
- Copy the Excel Chart using Ctrl + C
- Open a new PowerPoint Slide
- Press Ctrl + Alt + V, Paste Link
- This creates an OLE object in PowerPoint linked to the Excel chart.
Thanks for all your help!
@sukritisehgal,
Thank you very much for the instructions. I need some time to prepare a code example for you. I will get back to you as soon as possible.
Thanks, looking forward to working with you!
Hi Andrey,
It will be great if you can share this code in Java.
If that is an issue, Python is okay too!
@sukritisehgal,
Thank you for your request. I’ll need to dive into the API to meet your requirements, and I’ll get back to you as soon as I have an update.
@sukritisehgal,
Thank you for your patience. Unfortunately, I was unable to meet your requirements. I’ve forwarded your request to our developers.