Free Spire.Presentation for .NET(免费版)
Visual Studio
在E-iceblue官网或者Nuget网站上下载Free Spire.Presentation for .NET的安装包后,注意在编辑代码时,添加引用Spire.Presentation.dll到程序。dll文件可在安装路径下的Bin文件夹中获取。
方法1:加载多个独立的PowerPoint文件,同时将两个文档的数据合并后为一个新的PPT文件。using Spire.Presentation; namespace MergeSlides_PPT{ class Program { static void Main(string[] args) { //创建新的Presentation示例并删除默认的空白幻灯片 Presentation ppt = new Presentation(); ppt.Slides.RemoveAt(0); //加载需要合并的两个幻灯片文档 Presentation ppt1 = new Presentation('test1.pptx', FileFormat.Pptx2010); Presentation ppt2 = new Presentation('test2.pptx', FileFormat.Pptx2010); //插入ppt1的数据 for (int i = 0; i < ppt1.Slides.Count; i++) { ppt.Slides.Append(ppt1.Slides[i]); } //插入ppt2中的第一张幻灯片数据 ppt.Slides.Append(ppt2.Slides[0]); //保存ppt文档 ppt.SaveToFile('result.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('result.pptx'); } }}完成代码后,调试程序,生成文档。PPT文档合并前后效果对比,如下图所示:
方法2:将第1个幻灯片中指定的幻灯片数据,写入到第2个幻灯片,并保存为新的PPT文件。using Spire.Presentation; namespace MergeSlides2_PPT{ class Program { static void Main(string[] args) { //实例化Presentation类的对象,并加载幻灯片文档 Presentation ppt1 = new Presentation('test1.pptx', FileFormat.Pptx2010); //获取第一张幻灯片 ISlide slide = ppt1.Slides[0]; //加载第二个PowerPoint示例文档 Presentation ppt2 = new Presentation(); ppt2.LoadFromFile('test2.pptx', FileFormat.Pptx2010); //将ppt1中获取的第一个幻灯片数据插入到ppt2,并设置为第一页 int index = 0; ppt2.Slides.Insert(index, slide); //保存文档2 ppt2.SaveToFile('Merge2.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('Merge2.pptx'); } }}幻灯片合并前后效果对比,如下图: