Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Tue Mar 03, 2015 3:16 pm

Hi,

Do you have any methods or guidelines to work with embedded Excel tables?
We need to update data in table and another case is to insert new Excel table to PPT sheet. See attached example.

Evgeniy.Demur
 
Posts: 2
Joined: Thu Dec 11, 2014 9:27 pm

Wed Mar 04, 2015 9:43 am

Hello,

Thanks for your inquiry. We will provide the guideline accordingly ASAP.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Mar 05, 2015 5:34 am

Hello,

Well, first of all, you need to extract the Ole Objects with Spire.Presentation, then convert the ole data object to excel file will Spire.Xls, you may also use your own .Net code to save it to a Excel file, then change the data with Spire.xls, then replace the ole data with Spire.Presentation.
Code: Select all
Presentation ppt = new Presentation();
ppt.LoadFromFile("oletest.pptx");
IImageData image = null;
foreach (Spire.Presentation.IShape shape in ppt.Slides[0].Shapes)
        {
            //get the ole Object
            if (shape is Spire.Presentation.IOleObject)
            {
                Spire.Presentation.IOleObject oleobject = shape as Spire.Presentation.IOleObject;
                //save the ole object data to excel with Spire.Xls
                Workbook book = new Workbook();
                using (MemoryStream oleOblectMS = new MemoryStream())
                {
                    oleOblectMS.Write(oleobject.Data, 0, oleobject.Data.Length);
                    book.LoadFromStream(oleOblectMS);
                    //update the data
                    book.Worksheets["FAS"].Range["B2"].Value = "e-iceblue";
                    //convert the table you have changed to image, then add it to ppt
                    image = ppt.Images.Append(book.Worksheets["FAS"].SaveToImage(2, 2, 30, 6));
                    //then save the changed excel to byte[]
                    using (MemoryStream excelMS = new MemoryStream())
                    {
                        book.SaveToStream(excelMS);
                       //replace the data of original oleobject and the displayed image
                        excelMS.Position = 0;
                        oleobject.Data = excelMS.ToArray();
                        oleobject.SubstituteImagePictureFillFormat.Picture.EmbedImage = image;
                    }

                }
            }
        }
 ppt.SaveToFile("result.pptx", Spire.Presentation.FileFormat.Pptx2007);

Here is the code to insert ole to ppt for your reference.
Code: Select all
Workbook book = new Workbook();
book.LoadFromFile(fp.TestPath + "pptxtesta.xlsx");
Image image = book.Worksheets["FAS"].SaveToImage(2, 2, 30, 6);
Presentation ppt = new Presentation();
IImageData oleImage = ppt.Images.Append(image);
Rectangle rec = new Rectangle(0, 0, (int)ppt.SlideSize.Size.Width, (int)ppt.SlideSize.Size.Height);
using (MemoryStream ms = new MemoryStream())
        {
            book.SaveToStream(ms);
            ms.Position = 0;
            Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);
            oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
            oleObject.ProgId = "Excel.Sheet.12";
        }
ppt.SaveToFile("InsertOle.ppt", Spire.Presentation.FileFormat.Pptx2007);

Please note that there is two products(Spire.Presentation and Spire.Xls) used in the code, if you want to try the code, you need to use our Spire.Office product, you may only use Spire.Presentation and use your own .Net code to achieve the process of manipulating the excel.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Mar 10, 2015 9:17 am

Hello,

Have you tried the method? Does it fulfill your needs? Could you please give us some feedback at your convenience?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Mar 13, 2015 10:04 am

Thank you for decision! We'll test and get back to you.

P.S I got the email message about your question only today, post about the code and previous messages haven't been delivered to me. :-\

Evgeniy.Demur
 
Posts: 2
Joined: Thu Dec 11, 2014 9:27 pm

Return to Spire.Presentation