我正在使用GemBox.Presentation,我需要合并多个PPTX文件,并将它们合并为一个PPTX文件。
我尝试过:
PresentationDocument presentation1 = PresentationDocument.Load("PowerPoint1.pptx");
PresentationDocument presentation2 = PresentationDocument.Load("PowerPoint2.pptx");
foreach (Slide slide2 in presentation2.Slides)
presentation1.Slides.Add(slide2);
但是出现以下错误:
项目已包含在某些集合中。首先将其从该集合中删除。
参数名称:item
如何将多个演示文稿合并为一个演示文稿?
答案 0 :(得分:1)
使用AddCopy
方法之一代替Add
。
换句话说,请尝试以下操作:
var presentation1 = PresentationDocument.Load("PowerPoint1.pptx");
var presentation2 = PresentationDocument.Load("PowerPoint2.pptx");
// Merge "PowerPoint2.pptx" file into "PowerPoint1.pptx" file.
var context = CloneContext.Create(presentation2, presentation1);
foreach (var slide in presentation2.Slides)
presentation1.Slides.AddClone(slide, context);
// Save resulting "Merged PowerPoints.pptx" file.
presentation1.Save("Merged PowerPoints.pptx");
此外,您可以参考Cloning示例。