C# を使用した PowerPoint のスライド管理方法 | IronPPT

C# を使用して PowerPoint のスライドを管理する方法

This article was translated from English: Does it need improvement?
Translated
View the article in English

スライドは、プレゼンテーション内の 1 つのページまたは画面です。 コンテンツを整理および表示するための基本的な構成要素として機能します。 スライドは情報を視覚的に伝えるために使用され、テキスト、画像、グラフ、表、ビデオ、オーディオ、アニメーション、その他のデザイン要素を含めることができます。

クイックスタート: IronPPT を使用してスライドを簡単に削除、並べ替え、非表示にする

最初のスライドを追加した直後に削除する方法を示した 1 行の例を次に示します。 IronPPT を使用すると、開発者はスライドの管理などの一般的な操作を簡単に実行できるため、ツールではなくコンテンツに集中できます。

Nuget Icon今すぐ NuGet で PDF を作成してみましょう:

  1. NuGet パッケージ マネージャーを使用して IronPPT をインストールします

    PM > Install-Package IronPPT

  2. このコード スニペットをコピーして実行します。

    new PresentationDocument().AddSlide().Slides[0].Remove();
  3. 実際の環境でテストするためにデプロイする

    今すぐ無料トライアルでプロジェクトに IronPPT を使い始めましょう
    arrow pointer

スライドを追加

AddSlideメソッドを使用して、プレゼンテーションに新しいスライドを簡単に追加できます。 新しいスライドは現在のスライド リストの最後に追加されるため、プレゼンテーションをシームレスに拡張できます。

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-add-slide.cs
// Ensure you have the necessary using directives for any external libraries or namespaces.
using IronPPT;

// Instantiate a new PresentationDocument object.
var document = new PresentationDocument();

// Add three slides to the presentation.
// The AddSlide method creates a new slide and adds it to the list of slides in the document.
document.AddSlide();  // Add first slide
document.AddSlide();  // Add second slide
document.AddSlide();  // Add third slide

// Save the presentation to a file named "addSlides.pptx".
// The Save method takes a file path as an argument and writes the current state of the presentation to this file.
document.Save("addSlides.pptx");
' Ensure you have the necessary using directives for any external libraries or namespaces.
Imports IronPPT

' Instantiate a new PresentationDocument object.
Private document = New PresentationDocument()

' Add three slides to the presentation.
' The AddSlide method creates a new slide and adds it to the list of slides in the document.
document.AddSlide() ' Add first slide
document.AddSlide() ' Add second slide
document.AddSlide() ' Add third slide

' Save the presentation to a file named "addSlides.pptx".
' The Save method takes a file path as an argument and writes the current state of the presentation to this file.
document.Save("addSlides.pptx")
$vbLabelText   $csharpLabel

スライドを削除

Removeメソッドを使用して不要なスライドを削除します。 この機能により、全体の構造を崩すことなく、コンテンツを素早く調整し、不要なスライドを削除することができます。

ご注意すべてのスライドのインデックス位置はゼロベースのインデックスに従います。

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-remove-slide.cs
// Import the IronPPT namespace to handle PowerPoint presentations
// Assuming IronPPT is a fictional or placeholder library. Substitute with actual library as needed
using IronPPT;

// Create a new instance of the PresentationDocument class, assuming PresentationDocument 
// is a part of IronPPT that helps create or modify PowerPoint presentations
var document = new PresentationDocument();

// Add a new slide to the presentation, assuming the Add method adds a new slide to the collection
document.Slides.Add(new Slide());

// Check if there is at least one slide before attempting to remove
if (document.Slides.Count > 0)
{
    // Remove the first slide from the presentation's list of slides
    document.Slides.RemoveAt(0);
}

// Save the modified presentation to a file named "removeSlide.pptx"
// The Save method will write the current state of the presentation to the specified file
document.Save("removeSlide.pptx");
' Import the IronPPT namespace to handle PowerPoint presentations
' Assuming IronPPT is a fictional or placeholder library. Substitute with actual library as needed
Imports IronPPT

' Create a new instance of the PresentationDocument class, assuming PresentationDocument 
' is a part of IronPPT that helps create or modify PowerPoint presentations
Private document = New PresentationDocument()

' Add a new slide to the presentation, assuming the Add method adds a new slide to the collection
document.Slides.Add(New Slide())

' Check if there is at least one slide before attempting to remove
If document.Slides.Count > 0 Then
	' Remove the first slide from the presentation's list of slides
	document.Slides.RemoveAt(0)
End If

' Save the modified presentation to a file named "removeSlide.pptx"
' The Save method will write the current state of the presentation to the specified file
document.Save("removeSlide.pptx")
$vbLabelText   $csharpLabel

スライドの並べ替え

プレゼンテーションの流れに合わせてスライドの順序を並べ替えます。 スライドの並べ替えは簡単かつ効率的で、アイデアの順序を更新したり、新しい要件に適応したりすることが容易になります。

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-reorder-slide.cs
using IronPPT;

var document = new PresentationDocument();

// Adding a new slide to the document.
document.AddSlide();

// To reorder slides, we must remove the slide from its current position 
// and then insert it back at the desired position. 

// Capture the slide to be moved. 
// Assuming we want to move the first slide in this case.
var slideToMove = document.Slides[0];

// Remove the slide from its current position.
document.Slides.Remove(slideToMove);

// Add the slide back at the desired index (for example, index 1).
// Ensure the desired index is valid and within the range of the current slides.
if (document.Slides.Count >= 1) // Check if there is at least one slide to insert into.
{
    document.Slides.Insert(1, slideToMove);
}

// Save the presentation with the reordered slide.
// Ensure a valid file path and name are provided.
document.Save("reorderSlide.pptx");
Imports IronPPT

Private document = New PresentationDocument()

' Adding a new slide to the document.
document.AddSlide()

' To reorder slides, we must remove the slide from its current position 
' and then insert it back at the desired position. 

' Capture the slide to be moved. 
' Assuming we want to move the first slide in this case.
Dim slideToMove = document.Slides(0)

' Remove the slide from its current position.
document.Slides.Remove(slideToMove)

' Add the slide back at the desired index (for example, index 1).
' Ensure the desired index is valid and within the range of the current slides.
If document.Slides.Count >= 1 Then ' Check if there is at least one slide to insert into.
	document.Slides.Insert(1, slideToMove)
End If

' Save the presentation with the reordered slide.
' Ensure a valid file path and name are provided.
document.Save("reorderSlide.pptx")
$vbLabelText   $csharpLabel

スライドを非表示

プレゼンテーションに残したまま特定のスライドを非表示にします。 非表示のスライドはスライドショー中には表示されませんが、編集したり将来のプレゼンテーションで使用したりするためにアクセス可能です。

:path=/static-assets/ppt/content-code-examples/how-to/manage-slide-hide-slide.cs
using IronPPT;

// Create a new presentation document
var document = new PresentationDocument();

// Add a new slide to the presentation
document.AddSlide();

// Hide the first slide by setting its visibility to false
document.Slides[0].Visible = false;

// Save the presentation to a file named 'hideSlide.pptx'
document.Save("hideSlide.pptx");
Imports IronPPT

' Create a new presentation document
Private document = New PresentationDocument()

' Add a new slide to the presentation
document.AddSlide()

' Hide the first slide by setting its visibility to false
document.Slides(0).Visible = False

' Save the presentation to a file named 'hideSlide.pptx'
document.Save("hideSlide.pptx")
$vbLabelText   $csharpLabel
カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 3,325 | Version: 2025.11 リリース