Hi, I am trying to clone a new slide, and update objectData of the OleObjectFrameEx shape in the new slide without changing the original slide.
But when I open the saved presentation, I found the data in the original slide had been changed too.
Please help, following is code, and the original presentation is attached.
var present = new PresentationEx(@“C:\projects\test.pptx”);
var shape = (OleObjectFrameEx)present.Slides[0].Shapes[0];
using (Stream stream = new MemoryStream(shape.ObjectData))
{
Workbook wb = new Workbook(stream);
wb.Worksheets[1].Cells[1, 1].PutValue(0.1);
wb.Worksheets[1].Cells[2, 1].PutValue(0.2);
Bitmap imgChart = wb.Worksheets[0].Charts[0].ToImage();
var newImage = present.Slides[0].Parent.Images.AddImage(imgChart);
shape.Image = newImage;
using (MemoryStream msout = wb.SaveToStream())
{
msout.Position = 0;
shape.ObjectData = msout.ToArray();
}
}
present.Slides.InsertClone(1,present.Slides[0]);
shape = (OleObjectFrameEx) present.Slides[1].Shapes[0];
using (Stream stream = new MemoryStream(shape.ObjectData))
{
Workbook wb = new Workbook(stream);
wb.Worksheets[1].Cells[1, 1].PutValue(0.6);
wb.Worksheets[1].Cells[2, 1].PutValue(0.7);
Bitmap imgChart = wb.Worksheets[0].Charts[0].ToImage();
var newImage = present.Slides[1].Parent.Images.AddImage(imgChart);
shape.Image = newImage;
using (MemoryStream msout = wb.SaveToStream())
{
msout.Position = 0;
shape.ObjectData = msout.ToArray();
}
}
present.Save(@“C:\test001.pptx”,SaveFormat.Pptx);