Preserve Linking of OLE Objects to Excel When PPT Slide Is Inserted into Another Presentation

Hi
I have a use case where I have a PowerPoint with multiple OLE Objects that are linked to an Excel file.
I am sending the PowerPoint and Excel as base64 encoded strings via an API and will be inserting the slide into another presentation.
I want all the OLE objects to still be linked to the same Excel.
How can I do this ?


This Topic is created by vladimir.litvinchik using Email to Topic tool.

@sukritisehgal,
Thank you for contacting free support. I need some time to answer your question. I will get back to you as soon as possible.

Thanks, please let me know!

@sukritisehgal,
Thank you for your patience. I created a PowerPoint presentation (sample.pptx) and added an OLE object linked to the Excel file sample.xlsx on the slide. Then I ran the following code:

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

using var newPresentation = new Presentation();
newPresentation.Slides.RemoveAt(0);
newPresentation.Slides.AddClone(slide);
newPresentation.Save("output.pptx", SaveFormat.Pptx);

The OLE object in the output presentation remains linked to the same Excel file.
files.zip (72.7 KB)

Could you please provide step-by-step instructions on how to reproduce the issue you encountered?

Hi Andrey

Here is a more detailed description of the issue.
I have a Powerpoint file with ole objects, but all the ole links are broken because the excel file(with which the link was established in the first place) now has a new name and new location.

In order to re-establish the link manually, I go to File → Info → Edit Links to Files.
A pop up dialog appears. I do this for every link :

  1. Click on the link
  2. Click on change source
  3. Choose the new excel file from my file explorer
  4. Click ok
  5. The link now has the new excel file path and name but the SAME sheet name and cell structure. The type also changes from ??? to Worksheet. This part is very important because we want to preserve the sheet name and cell structure.
  6. After changing source for all links, Click on Update now
    This updates all ole links

How can I accomplish this programmatically using Aspose Cells for Python via .NET ?
Thanks for your continued help

@sukritisehgal,
Thank you for the details. I need some time to check the issue. I will get back to you as soon as possible.

@sukritisehgal,
Thank you for your patience. To update the file path to a linked object, please try using the setLinkPathLong method from the IOleObjectFrame interface. The following code example shows how to do this.

Presentation presentation = new Presentation("sample.pptx");

// Let’s say that the first slide contains a single OLE object.
ISlide slide = presentation.getSlides().get_Item(0);
IOleObjectFrame oleFrame = (IOleObjectFrame) slide.getShapes().get_Item(0);

oleFrame.setLinkPathLong("put_new_file_path_here");

presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();

I tried setLinkPathLong and this still doesn’t re-establish the link.

If I go to File → Info → Edit Links to Files. the type of each link is ???
On hitting Change Source and re-establishing the link, the type changes to Worksheet.

How can I programmatically update the type of link to Worksheet ?

Never mind, I got this to work. Set Link path long helped.

Quick question, when the link breaks, the OLE objects get resized and move around.
After re-establishing the link and doing Right Click → Update Link, the linking comes back and the OLE objects also move to the correct size.

Is there a way to make sure the OLE Objects in the PowerPoint slide are in the right size ?
I.e. the same size and shape that they should be in after clicking on Update Link on that shape.

@sukritisehgal,
This is how PowerPoint behaves. I think the only way to ensure that OLE objects are the correct size on a PowerPoint slide is to recreate the image.

Hey Andrey,

I am converting my pptx(with links to Excel) to a base64 String and then converting it back to a pptx on another host.
I found a way to set the link so that linking does NOT break even after converting the base64 back into thee pptx. This way I do NOT have to re-set the link
However the OLE objects still get totally distorted.
They appear fine after I do Right Click → Update Link.

Can you please help me with some way the OLE objects do not get distorted after converting from base64 back to pptx ?
We really need this, and will not be able to roll this out to users if we are not able to solve the OLE distortion issue.
Will appreciate any help here!
Thanks

@sukritisehgal,
Unfortunately, I was unable to reproduce the issue you described. I used the following code example to convert a sample presentation file to a base64 string.

byte[] fileBytes = Files.readAllBytes(sourcePath);
String base64String = Base64.getEncoder().encodeToString(fileBytes);

Then, I saved the string back to a file with another folder path.

byte[] decodedBytes = Base64.getDecoder().decode(base64String);
Files.write(outputPath, decodedBytes);

I also deleted the source file and moved the linked Excel file to the new folder. When I open the presentation file, no issues appear on my end.
sample.zip (30.7 KB)

Could you please share step-by-step instructions and sample files so that we can reproduce the issue you encountered?

Hi Andrey,

I am using the Office JS Library to insert the slide from Base64.
Here is my code snippet :

  context.presentation.insertSlidesFromBase64(chosenFileBase64, {
      formatting: "UseDestinationTheme",
      targetSlideId: selectedSlideID + "#",
    });

When the slide is inserted, the OLE objects get all distorted.
They come back to their size after hitting Right Click → update Link on each object but they are initially completely out of shape.

@sukritisehgal,
Thank you for the details. Unfortunately, I cannot reproduce the issue using the information you provided. Please share the sample files.