プレゼンテーションにスライドを追加
プレゼンテーションにスライドを追加
プレゼンテーションファイルにスライドを追加することについて話す前に、スライドに関するいくつかの事実を議論しましょう。各PowerPointプレゼンテーションファイルにはマスター/レイアウトスライドと他の通常スライドが含まれています。つまり、プレゼンテーションファイルには少なくとも1つ以上のスライドが含まれているということです。スライドのないプレゼンテーションファイルはAspose.Slides for C++ではサポートされていないことを知っておくことが重要です。各スライドにはユニークなIDがあり、すべての通常スライドはゼロベースのインデックスによって指定された順序で配置されています。Aspose.Slides for C++は、開発者がプレゼンテーションに空のスライドを追加できるようにします。プレゼンテーションに空のスライドを追加するには、以下の手順に従ってください。
- Presentationクラスのインスタンスを作成します。
- Presentationオブジェクトが公開しているSlides(コンテンツスライドオブジェクトのコレクション)プロパティへの参照を設定することで、ISlideCollectionクラスのインスタンスを作成します。
- ISlideCollectionオブジェクトが公開しているAddEmptySlideメソッドを呼び出して、コンテンツスライドコレクションの最後に空のスライドを追加します。
- 新たに追加した空のスライドで作業を行います。
- 最後に、Presentationオブジェクトを使用してプレゼンテーションファイルを書き込みます。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../templates/AddSlides.pptx"; | |
// Instantiate Presentation class that represents the presentation file | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Instantiate SlideCollection calss | |
SharedPtr<ISlideCollection> slds = pres->get_Slides(); | |
for (int i = 0; i < pres->get_LayoutSlides()->get_Count(); i++) | |
{ | |
// Add an empty slide to the Slides collection | |
slds->AddEmptySlide(pres->get_LayoutSlides()->idx_get(i)); | |
} | |
// Save the PPTX file to the Disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |