本文介绍了将演示文稿合并为单个演示文稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 GemBox.Presentation,我需要合并多个 PPTX 文件,将它们组合成单个 PPTX 文件.
I'm using GemBox.Presentation and I need to merge multiple PPTX files, combine them into a single PPTX file.
我试过了:
PresentationDocument presentation1 = PresentationDocument.Load("PowerPoint1.pptx"); PresentationDocument presentation2 = PresentationDocument.Load("PowerPoint2.pptx"); foreach (Slide slide2 in presentation2.Slides) presentation1.Slides.Add(slide2);但我收到以下错误:
项目已包含在某个集合中.首先将其从该集合中删除.参数名称:item
Item is already contained in some collection. Remove it from that collection first. Parameter name: item
如何将多个演示文稿合并为一个演示文稿?
How can I merge several presentations into one presentation?
推荐答案使用 AddCopy 方法而不是 Add.换句话说,试试这个:
Use one of the AddCopy methods instead of Add. In other words, try this:
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");另外,您可以参考克隆示例.
Also, you can refer to Cloning example.
更多推荐
将演示文稿合并为单个演示文稿
发布评论