Change values in embedded excel sheet

Hello,

currently, I’m evaluating Aspose.Slides and Aspose.Cells for a new project.
The main requirement is to change the values in some excel sheets,
that are embedded (as OleObjects) in a powerpoint presentation.

The GitHub example:
https://github.com/aspose-slides/Aspose.Slides-for-.NET/blob/master/Examples/CSharp/Shapes/ChangeOLEObjectData.cs
seems to be the perfect solution.

Unfortunately, the code line:
Wb = new Aspose.Cells.Workbook(msln);
throws the following exception:
{“This file’s format is not supported or you don’t specify a correct format.”}

I’m using Office 2016, Aspose.Slides 17.2 and Aspose.Cells 17.3
(both installed via NuGet today).

The OleObject has the ProgId Excel.Sheet.12

I attached the pptx file, used for testing.

Can you help me?

With kind regards
Klaus

Hi Klaus,

Thanks for inquiring Aspose.Slides.

I have observed the issue shared by you and have observed that the embedded object ID is not an excel file but a TCLLayout active document. For your kind reference, I have attached image mentioning the extacted OLE type. Can you please verify this on your end. For this reason, exception is raised by Aspose.Cell as it is not supported type.

Many Thanks,

Hello,

yes, the first OleObject on the slide has the ProgId "TCLayout.ActiveDocument.1"
an no, I did NOT try to open this OleObject as a workbook.

I focused on the OleObject with the ProgId “Excel.Sheet.12” (Shape.Name = Objekt 3)
which relates to the Excel sheet that you can see on the slide.

I attached the (slightly modified) example I used and a screenshot of the exception.

With kind regards,
Klaus

Hi Klaus,

I have observed your further comments and have tried saving the extracted Ole to MS Excel file using FileStream. It too generated the corrupt file and for reference, I have attached that in this thread. We need to figure out if the embedded OLE has corrupted file or there is any issue in Aspose.Slides to extract data. An issue with ID SLIDESNET-38503 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be fixed.


Many Thanks,

Hi,

I do not think that the embedded Ole data is corrupt.

When you open the originally attached presentation in Powerpoint,
you can edit the embedded excel sheet without any problem.


When you execute just the following two code lines:

Presentation pres = new Presentation(@“C:\Presentation\Powerpoint_Excel_Dummy.pptx”);
pres.Save(@“C:\Presentation\Test.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);

the resulting presentation ‘Test.pptx’ is corrupt.

The embedded excel sheet cannot be used any more in Powerpoint.

I hope you find a solution soon.

Kind regards,
Klaus

Hi Klaus,

Thank you for sharing the feedback. As I shared with you earlier that the issue may possibly be owing to corrupted OLE Object or there is some problem with Aspose.Slides while extracting OLE data. Our product team will be investigating the issue on their end and we will share the good news with you as soon as the feedback will be shared by our product team.

Many Thanks,

Hi Klaus,

Our product team has investigated the issue on their end. Actually, the data which is contained in
OleObjectFrame.ObjectData property is not a genuine Excel document. Please note that embedded Office documents are not stored in presentation as a document itself, but as an OLE container. We don’t have a public API which will allow extracting this stream and using as ready-to-use Excel document, but it can be easily achieved using third-party open source library, such as OpenMcdf.

First of all, you need to reference this library. It’s available as NuGet package, and you can add it to your project using Package Manager Console:

Install-Package OpenMcdf or using “Manage Nuget Packages” tool (or just download the library and reference it directly). Then, the following sample code can be used to work with embedded document using Aspose.Cells:

public static void ExtractOle()
{

    Presentation pres = new Presentation(@"Powerpoint_Excel_Dummy.pptx");


    foreach (var slide in pres.Slides)
    {

        Console.WriteLine("Slide #{0}: {1} shapes", slide.SlideNumber, slide.Shapes.Count());


        foreach (var shape in slide.Shapes.OrderBy((s) => s.Name))
        {

            Console.WriteLine("- {0} - {1}", shape.ToString(), shape.Name);


            if (shape is OleObjectFrame)
            {

                if ("Objekt 3".Equals(shape.Name))
                {

                    OleObjectFrame ole = shape as OleObjectFrame;

                    if ((ole != null) && ("Worksheet".Equals(ole.ObjectName)))
                    {

                        using (MemoryStream memoryStream = new MemoryStream(ole.ObjectData))
                        {

                            OpenMcdf.CompoundFile compoundFile = new CompoundFile(memoryStream);

                            OpenMcdf.CFStream stream = compoundFile.RootStorage.GetStream("Package");

                            byte[] packageData = stream.GetData();


                            using (MemoryStream packageDataStream = new MemoryStream(packageData))
                            {

                                Workbook wb = new Workbook(packageDataStream);

                                Worksheet ws = wb.Worksheets[0];

                                using (MemoryStream msOut = new MemoryStream())
                                {

                                    wb.Save(msOut, Aspose.Cells.SaveFormat.Xlsx);

                                }

                            }

                        }

                    }

                }

            }

        }

    }


    pres.Save(@"Test.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

}

Many Thanks,

Mudassir Fayyaz