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.
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);
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);