将演示文稿合并为单个演示文稿
Merging presentations into single presentation
我正在使用 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 is already contained in some collection. Remove it from that collection first.
Parameter name: item
如何将多个演示文稿合并为一个演示文稿?
使用 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例子。
我正在使用 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 is already contained in some collection. Remove it from that collection first.
Parameter name: item
如何将多个演示文稿合并为一个演示文稿?
使用 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例子。