翻譯|使用教程|編輯:李顯亮|2021-03-15 09:50:34.083|閱讀 294 次
概述:有時可能需要合并這些演示文稿以用于共享或文檔目的。手動執行此任務將非常耗時。有效的方法是以編程方式實現這一目標。在本文中,將學習 如何使用C ++合并PowerPoint演示文稿。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PowerPoint演示文稿可用于許多情況下,例如會議,演示文稿,討論等。在某些情況下,可能會有單獨的人創建不同的演示文稿或在各種會議中使用單獨的演示文稿。有時可能需要合并這些演示文稿以用于共享或文檔目的。手動執行此任務將非常耗時。有效的方法是以編程方式實現這一目標。在本文中,將學習 如何使用C ++合并PowerPoint演示文稿。
Aspose.Slides for C ++是一個C ++庫,提供了許多用于PowerPoint演示文稿的功能。該API使您無需使用Microsoft PowerPoint即可創建,修改和轉換PowerPoint演示文稿。此外,API還提供了合并不同PowerPoint文件的功能。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
使用Aspose.Slides for C ++合并兩個演示文稿的過程很容易。為此,需要加載兩個演示文稿,在源演示文稿幻燈片中循環,然后將其克隆添加到目標演示文稿中。以下是合并兩個PowerPoint演示文稿的步驟。
以下是使用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 class SharedPtrpresentation1 = MakeObject(sourceFilePath1); SharedPtrpresentation2 = MakeObject(sourceFilePath2); for (SharedPtrslide : presentation2->get_Slides()) { // Merge slides from source to destination presentation1->get_Slides()->AddClone(slide); } // Save the presentation presentation1->Save(outputFilePath, SaveFormat::Pptx);
下圖顯示了源,目標和合并的演示文稿文件。
目標PowerPoint演示文稿圖像
源PowerPoint演示文稿圖像
合并的PowerPoint演示文稿圖像
在某些情況下,您可能對整個演示文稿不感興趣,而想要添加幻燈片的子集。為此,請在循環源演示文稿幻燈片的同時添加必要的條件。以下是合并選定的PowerPoint幻燈片的步驟。
以下是使用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 files SharedPtrpresentation1 = MakeObject(sourceFilePath1); SharedPtrpresentation2 = MakeObject(sourceFilePath2); for (int i = 0; i < presentation2->get_Slides()->get_Count(); i++) { // Merge only even slides if (i % 2 == 0) { presentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(i)); } } // Save the presentation presentation1->Save(outputFilePath, SaveFormat::Pptx);
下圖顯示了合并的演示文稿文件。源和目標演示文稿文件與上一個示例中使用的文件相同。
合并的PowerPoint演示文稿圖像
在前兩個示例中,源演示文稿和目標演示文稿的設計是相同的。下圖顯示了將演示文稿與不同設計合并的結果。
目標PowerPoint演示文稿圖像
源PowerPoint演示文稿圖像
合并的PowerPoint演示文稿圖像
您可以在合并的演示文稿圖像中看到第三張幻燈片在合并過程中保留了其原始樣式。如果您希望源幻燈片使用目標演示文稿樣式,請使用以下步驟。
以下是使用幻燈片母版合并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 files SharedPtrpresentation1 = MakeObject(sourceFilePath1); SharedPtrpresentation2 = MakeObject(sourceFilePath2); // Merge the first slide using slide master presentation1->get_Slides()->AddClone(presentation2->get_Slides()->idx_get(0), presentation1->get_Masters()->idx_get(0), true); // Save the presentation presentation1->Save(outputFilePath, SaveFormat::Pptx);
下圖顯示了以上示例代碼生成的合并演示文稿。
將PowerPoint演示文稿與使用目標演示文稿樣式添加的第一張幻燈片合并
如果你想試用Aspose的全部完整功能,可 聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn