PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

  • 使用C ++合并PowerPoint演示文稿
  • 使用C ++合并特定的PowerPoint幻灯片
  • 使用幻灯片母版合并PowerPoint演示文稿

Aspose.Slides for C ++是一个C ++库,提供了许多用于PowerPoint演示文稿的功能。该API使您无需使用Microsoft PowerPoint即可创建,修改和转换PowerPoint演示文稿。此外,API还提供了合并不同PowerPoint文件的功能。

>>你可以点击这里下载Aspose.Slides 最新版测试体验。

整合所有格式API处理控件Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部!


使用C ++合并PowerPoint演示文稿

使用Aspose.Slides for C ++合并两个演示文稿的过程很容易。为此,需要加载两个演示文稿,在源演示文稿幻灯片中循环,然后将其克隆添加到目标演示文稿中。以下是合并两个PowerPoint演示文稿的步骤。

  • 使用Presentation 类加载目标PowerPoint文件。
  • 创建Presentation 类的另一个实例以表示源PowerPoint文件。
  • 使用Presentation-> get_Slides()方法从源演示文稿中检索幻灯片 并对其进行迭代。
  • 在循环内部,使用Presentation-> get_Slides()-> AddClone(System :: SharedPtrsourceSlide)方法将每张幻灯片添加到目标演示文稿中。
  • 最后,使用Presentation-> Save(系统::字符串名称,导出:: SaveFormat格式)方法保存合并的演示文稿文件 。

以下是使用C ++合并PowerPoint演示文稿的示例代码。

// The path to the documents directory.const String sourceFilePath1 = u"SourceDirectory\SamplePresentation2.pptx";const String sourceFilePath2 = u"SourceDirectory\SamplePresentation3.pptx";const String outputFilePath = u"OutputDirectory\mergedPresentation.pptx";// Instantiate Presentation classSharedPtrpresentation1 = MakeObject(sourceFilePath1);SharedPtrpresentation2 = MakeObject(sourceFilePath2);for (SharedPtrslide : presentation2->get_Slides()){// Merge slides from source to destinationpresentation1->get_Slides()->AddClone(slide);}// Save the presentationpresentation1->Save(outputFilePath, SaveFormat::Pptx);

下图显示了源,目标和合并的演示文稿文件。

目标PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

源PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

合并的PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

使用C ++合并特定的PowerPoint幻灯片

在某些情况下,您可能对整个演示文稿不感兴趣,而想要添加幻灯片的子集。为此,请在循环源演示文稿幻灯片的同时添加必要的条件。以下是合并选定的PowerPoint幻灯片的步骤。

  • 首先,使用Presentation 类加载目标PowerPoint文件。
  • 创建Presentation 类的另一个实例以表示源PowerPoint文件。
  • 使用Presentation-> get_Slides()方法从源演示文稿中检索幻灯片 并对其进行迭代。
  • 在循环内部,使用Presentation-> get_Slides()-> AddClone(System :: SharedPtrsourceSlide)方法将所需的幻灯片添加到目标演示文稿中。
  • 最后,使用Presentation-> Save(系统::字符串名称,导出:: SaveFormat格式)方法保存合并的演示文稿文件 。

以下是使用C ++合并选定的PowerPoint幻灯片的示例代码。

// The path to the documents directory.const String sourceFilePath1 = u"SourceDirectory\SamplePresentation2.pptx";const String sourceFilePath2 = u"SourceDirectory\SamplePresentation3.pptx";const String outputFilePath = u"OutputDirectory\mergedPresentation.pptx";// Load the presentation filesSharedPtrpresentation1 = MakeObject(sourceFilePath1);SharedPtrpresentation2 = MakeObject(sourceFilePath2);for (int i = 0; i < presentation2->get_Slides()->get_Count(); i++){// Merge only even slidesif (i % 2 == 0){presentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(i));}}// Save the presentationpresentation1->Save(outputFilePath, SaveFormat::Pptx);

下图显示了合并的演示文稿文件。源和目标演示文稿文件与上一个示例中使用的文件相同。

合并的PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

使用幻灯片母版合并PowerPoint演示文稿

在前两个示例中,源演示文稿和目标演示文稿的设计是相同的。下图显示了将演示文稿与不同设计合并的结果。

目标PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

源PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

合并的PowerPoint演示文稿图像

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

您可以在合并的演示文稿图像中看到第三张幻灯片在合并过程中保留了其原始样式。如果您希望源幻灯片使用目标演示文稿样式,请使用以下步骤。

  • 使用Presentation 类加载目标PowerPoint文件。
  • 创建Presentation 类的另一个实例以表示源PowerPoint文件。
  • 使用Presentation-> get_Slides()-> AddClone(System :: SharedPtrsourceSlide,System :: SharedPtrdestMaster,bool allowCloneMissingLayout)方法将所需的幻灯片添加到目标演示文稿中。
  • 最后,使用Presentation-> Save(系统::字符串名称,导出:: SaveFormat格式)方法保存合并的演示文稿文件 。

以下是使用幻灯片母版合并PowerPoint演示文稿的示例代码。

// The path to the documents directory.const String sourceFilePath1 = u"SourceDirectory\SamplePresentation.pptx";const String sourceFilePath2 = u"SourceDirectory\SamplePresentation3.pptx";const String outputFilePath = u"OutputDirectory\mergedPresentation.pptx";// Load the presentation filesSharedPtrpresentation1 = MakeObject(sourceFilePath1);SharedPtrpresentation2 = MakeObject(sourceFilePath2);// Merge the first slide using slide masterpresentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(0), presentation1->get_Masters()->idx_get(0), true);// Save the presentationpresentation1->Save(outputFilePath, SaveFormat::Pptx);

下图显示了以上示例代码生成的合并演示文稿。

将PowerPoint演示文稿与使用目标演示文稿样式添加的第一张幻灯片合并

PPT处理控件Aspose.Slides功能演示:使用C ++合并PowerPoint演示文稿

如果你想试用Aspose的全部完整功能,可 联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月12日
下一篇 2021年1月12日

相关推荐

发表回复

登录后才能评论