Change of OLE Objects does not work

Hi Aspose team,



during test today I figured that I cannot make replacement of OLE Objects in my Powerpoint presentation.



I createded following cases:

1. Object => Create from file => only PDF document selected

2. Object => Create from file => Link checkbox selected

3. Object => Create from file => Display as icon selected

4. Object => Created from file => Link and Display as icon selected



You can see everything in attached document OLE.pptx



At first I tried to use LinkPathLong and LinFileName to make “brute-force” change there but then I noticed that they are read-only properties so I tried new approach.



By using following code:



//Reading object data in Workbook

Aspose.Cells.Workbook Wb;



using (System.IO.MemoryStream msln = new System.IO.MemoryStream())

{

Wb = new Aspose.Cells.Workbook(msln);



using (System.IO.MemoryStream msout = new System.IO.MemoryStream())

{

//Modifying the workbook data

Wb.Worksheets[0].Cells[0, 4].PutValue(“E”);

Wb.Worksheets[0].Cells[1, 4].PutValue(12);

Wb.Worksheets[0].Cells[2, 4].PutValue(14);

Wb.Worksheets[0].Cells[3, 4].PutValue(15);



Aspose.Cells.OoxmlSaveOptions so1 = new Aspose.Cells.OoxmlSaveOptions(Aspose.Cells.SaveFormat.Xlsx);



Wb.Save(msout, so1);



//Changing Ole frame object data

msout.Position = 0;

oof.ObjectData = msout.ToArray();

oof.UpdateAutomatic = true;

}

}



I wanted to replace my PDF OLE Object with generated Excel table with idea that later when I start my search and replace process I’ll read into memory stream new file and “paste” it as a new OLE Object.



By running example I am not getting any error but when I open PPTX document I do not see any difference. In output file you will see that PDF files are still part of the document.



Am I missing/doing something wrong?



What would be the best approach in scenarios where OLE objects should be replaced? Is there any option to replace only links to OLE Objects and then on document openning that they are updated?





Project and test documents are attached.



Thanks,

Oliver

Hi Oliver,

Thanks for your interest in Aspose.Slides.

I have worked with the sample project shared by you and have observed that your source Ole frames inside slides are of PDF types and you are trying to replace the data of PDF with that of Excel file. However, you are not changing ObjectName and ID for the Ole Frame that is supported of Excel object. As a result of this the Ole frames are still expecting PDF data which is replaced by excel file data and got corrupted. Therefore, you need to change the ObjectName and ID for the Ole Frame that is supported of Excel object. Please try using the following sample code to serve the purpose.


public static void Powerpnt()
{
//string dataDir = Path.GetFullPath("…/…/…/…/…/…/_Work/Aspose/Powerpoint/");
string dataDir = @“C:\Users\Mudassir\Downloads\Powerpoint\PDF\PDF\bin\Debug”;

Console.WriteLine(DateTime.Now.ToString());
Presentation pres = new Presentation(dataDir + “OLE.pptx”);
foreach (ISlide slide in pres.Slides)
{
//Cast the shape to OleObjectFrame
foreach (Shape shp in slide.Shapes)
{
if (shp is OleObjectFrame)
{
OleObjectFrame oof = (OleObjectFrame)shp;

//Read the OLE Object and write it to disk
if (oof != null)
{
Console.WriteLine("LinkFileName: " + oof.LinkFileName);
Console.WriteLine("LinkPathLong: " + oof.LinkPathLong);
Console.WriteLine("Name: " + oof.Name);
Console.WriteLine("ObjectName: " + oof.ObjectName);
Console.WriteLine("ObjectProgId: " + oof.ObjectProgId);
Console.WriteLine();

//Reading object data in Workbook
Aspose.Cells.Workbook Wb;

using (System.IO.MemoryStream msln = new System.IO.MemoryStream())
{
Wb = new Aspose.Cells.Workbook(msln);

using (System.IO.MemoryStream msout = new System.IO.MemoryStream())
{
//Modifying the workbook data
Wb.Worksheets[0].Cells[0, 4].PutValue(“E”);
Wb.Worksheets[0].Cells[1, 4].PutValue(12);
Wb.Worksheets[0].Cells[2, 4].PutValue(14);
Wb.Worksheets[0].Cells[3, 4].PutValue(15);

oof.ObjectProgId = “Excel.Sheet.12”;
oof.ObjectName = “Worksheet”;
Aspose.Cells.OoxmlSaveOptions so1 = new Aspose.Cells.OoxmlSaveOptions(Aspose.Cells.SaveFormat.Xlsx);
Wb.Save(msout, so1);

//Changing Ole frame object data
msout.Position = 0;
oof.ObjectData = msout.ToArray();
oof.UpdateAutomatic = true;
}
}


}


}
}
}
pres.Save(dataDir + “output2.pptx”,Aspose.Slides.Export.SaveFormat.Pptx);
}

Please share, if I may help you further in this regard.

Many Thanks,

Problem resolved :-).
Thanks a lot for quick help.

BR,
Oliver