Sorry for my English :)
I try to copy a chart element from one presentation to another with the same position
using C =DocumentFormat.OpenXml.Drawing.Charts;
namespace OpenXmlApp{publicclassShapeReader{publicstaticvoidCopyChart(string sourPrePath,string destPrePath){
using (var sourDoc =PresentationDocument.Open(sourPrePath,false)){
using (var destDoc =PresentationDocument.Open(destPrePath,true)){// Get copy of graphic frame.var sourGraphicFrameCopy = sourDoc.PresentationPart.SlideParts.First().Slide.CommonSlideData.ShapeTree.GetFirstChild<P.GraphicFrame>().CloneNode(true);// Add copy of graphic frame to destinition slide.var destSlidePart = destDoc.PresentationPart.SlideParts.First();var destShapeTree = destSlidePart.Slide.CommonSlideData.ShapeTree;
destShapeTree.Append(sourGraphicFrameCopy);// Add chart part to destinition slide.var sourChartPart = sourDoc.PresentationPart.SlideParts.First().ChartParts.First();var addedChartPart = destSlidePart.AddNewPart<ChartPart>();
addedChartPart.FeedData(sourChartPart.GetStream());// Link added graphic frame and added chart part.var chartRef = sourGraphicFrameCopy.Descendants<C.ChartReference>().SingleOrDefault();var addedChartPartId = destSlidePart.GetIdOfPart(addedChartPart);
chartRef.Id= addedChartPartId;
destDoc.Save();}}}
but this code just broke presentation - PowerPoint tries to restore the result presentation.
How correctly copy chart element?