スライド
本記事では、Aspose.Slides for .NET を使用してスライドを操作する方法を示す一連の例を提供します。Presentation クラスを使用してスライドの追加、取得、クローン、並べ替え、削除方法を学びます。
以下の各例は、簡単な説明と C# のコードスニペットで構成されています。
スライドの追加
新しいスライドを追加するには、まずレイアウトを選択する必要があります。この例では Blank レイアウトを使用し、プレゼンテーションに空のスライドを追加します。
static void Add_Slide()
{
using var pres = new Presentation();
// 各スライドはレイアウトに基づいており、レイアウト自体はマスタースライドに基づいています。
// 新しいスライドを作成するには Blank レイアウトを使用します。
var blankLayout = pres.LayoutSlides.GetByType(SlideLayoutType.Blank);
// 選択したレイアウトを使用して新しい空のスライドを追加します
pres.Slides.AddEmptySlide(layout: blankLayout);
}
💡 Tip: Each slide layout is derived from a master slide, which defines the overall design and placeholder structure. The image below illustrates how master slides and their associated layouts are organized in PowerPoint.

Access Slides by Index
You can access slides using their index, or find a slide’s index based on a reference. This is useful for iterating through or modifying specific slides.
static void Access_Slide()
{
// デフォルトでは、プレゼンテーションは空のスライドが 1 つ作成されます。
using var pres = new Presentation();
// もう1つ空のスライドを追加します
pres.Slides.AddEmptySlide(layout: pres.LayoutSlides.GetByType(SlideLayoutType.Blank));
// インデックスでスライドにアクセスします
var firstSlide = pres.Slides[0];
var secondSlide = pres.Slides[1];
// 参照からスライドのインデックスを取得し、インデックスでアクセスします
var secondSlideIndex = pres.Slides.IndexOf(secondSlide);
var secondSlideByIndex = pres.Slides[secondSlideIndex];
}
Clone a Slide
This example demonstrates how to clone an existing slide. The cloned slide is automatically added to the end of the slide collection.
static void Clone_Slide()
{
// デフォルトでは、プレゼンテーションには空のスライドが 1 つ含まれています。
using var pres = new Presentation();
// 最初のスライドをクローンします。クローンされたスライドはプレゼンテーションの最後に追加されます。
var clonedSlide = pres.Slides.AddClone(sourceSlide: pres.Slides[0]);
// クローンされたスライドのインデックスは 1 です(プレゼンテーションの2番目のスライド)。
var clonedSlideIndex = pres.Slides.IndexOf(clonedSlide);
}
Reorder Slides
You can change the order of slides by moving one to a new index. In this case, we move a cloned slide to the first position.
static void ReOrder_Slide()
{
using var pres = new Presentation();
// 最初のスライド(デフォルトで作成される)のクローンを追加します。
var clonedSlide = pres.Slides.AddClone(pres.Slides[0]);
// クローンされたスライドを最初の位置に移動します(他のスライドは下にシフトします)。
pres.Slides.Reorder(index: 0, clonedSlide);
}
Remove a Slide
To remove a slide, simply reference it and call Remove. This example adds a second slide and then removes the original, leaving only the new one.
static void Remove_Slide()
{
using var pres = new Presentation();
// デフォルトの最初のスライドに加えて、新しい空のスライドを追加します。
var secondSlide = pres.Slides.AddEmptySlide(layout: pres.LayoutSlides.GetByType(SlideLayoutType.Blank));
// 最初のスライドを削除します。新しく追加されたスライドだけが残ります。
var firstSlide = pres.Slides[0];
pres.Slides.Remove(firstSlide);
}