透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
PowerPoint プレゼンテーションは、ビジネスレポート、営業プレゼンテーション、学術講義、ソフトウェア生成のダッシュボードに不可欠です。 しかし、手動でPowerPointスライドを作成することは退屈で時間がかかることがあります。
インターロップライブラリをダウンロードする必要なく、C#でPowerPoint作成を自動化できたら素晴らしいと思いませんか? そこで、Iron Software の強力な PowerPoint ライブラリ、IronPPTが役立ちます。 IronPPTは、開発者がプログラムにより簡単にPowerPointプレゼンテーションを作成、修正、エクスポートできる強力な.NETライブラリで、Microsoft PowerPointインターロップライブラリを必要としません。 スライドを動的に生成したり、チャートを挿入したり、プレゼンテーションをPDFに変換したりする必要がある場合、IronPPTはシンプルで効果的なソリューションを提供します。
今日は、IronPPTを使用してC#でPowerPointプレゼンテーションを作成する方法を探ります。 私たちは以下をカバーします:
PowerPoint自動化のベストプラクティス
さあ、始めましょう! 🚀
プログラムによってプレゼンテーションを作成する前に、まず開発環境を設定しましょう。
IronPPTを使用するには、C#プロジェクトにNuGetパッケージをインストールします。
Visual Studioを開きます。
パッケージ マネージャー コンソール を開きます (ツール > NuGet パッケージ マネージャー > パッケージ マネージャー コンソール)。
Install-Package IronPPT
4. または、「ツール -> NuGet パッケージ マネージャー -> ソリューションの NuGet パッケージの管理」に移動し、IronPPT を検索して「インストール」をクリックすることでインストールできます。

5. 新しいコンソールアプリケーションプロジェクトを作成します。
インストールが完了すると、.NET Framework 内で PowerPoint プレゼンテーションの作成を開始できます。
## **C#でのPowerPointプレゼンテーションの作成**
### **1. PowerPointファイルの初期化**
PowerPointの自動化の最初のステップは、新しいPowerPointファイルを作成することです。IronPPTを使用すると、プログラムでPowerPointプレゼンテーションを生成し、.pptxファイルとして保存することができます。 デフォルトでは、生成されたPowerPointファイルはMicrosoft PowerPoint、Googleスライド、および**.pptx形式**をサポートする他のソフトウェアと互換性があります。 本日の例では、新しいVisual Studioプロジェクトを作成します。
では、最初のコード例として、新しい空のパワーポイントプレゼンテーションファイルを[作成](https://ironsoftware.com/csharp/ppt/examples/create-empty-presentation/)します。これは出発点となるものであり、後でテキスト、スタイリングなどを追加できるシンプルなパワーポイントプレゼンテーションファイルです。
```cs
using IronPPT;
class Program
{
static void main()
{
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
// Save the blank file presentation
ppt.Save("example.pptx");
}
}
出力ファイル
新しいプレゼンテーションをPowerPointプログラムで開くと、現時点で含まれているのは1枚の空白のスライドだけであることがわかります。
PowerPointプレゼンテーションは複数のスライドで構成されており、それぞれが異なるレイアウト、テキスト、画像、デザイン要素を持つことができます。 IronPPTを使用すると、プレゼンテーションにスライドを動的に追加し、そのレイアウトを変更し、プログラムでコンテンツを挿入できます。 これは、レポート自動化システム、ダッシュボードのエクスポート、およびプレゼンテーションの生成に役立ちます。
この時点で、私たちのPowerPointドキュメントは内容や追加のスライドがない単一の空白スライドだけです。 では、PowerPoint プレゼンテーションにスライドを追加し始める方法を見てみましょう。
using IronPPT;
using IronPPT.Models;
// Loading in our presentation file
var ppt = new PresentationDocument("output.pptx");
ppt.AddSlide();
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Loading in our presentation file
var ppt = new PresentationDocument("output.pptx");
ppt.AddSlide();
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Loading in our presentation file
Private ppt = New PresentationDocument("output.pptx")
ppt.AddSlide()
ppt.Save("output.pptx")
出力
🔹 このような単純なスライドを追加するだけでなく、IronPPT を使用して複数のスライドを追加し、それらを動的に変更することができます。 例では、プレゼンテーションに2枚のスライドのみを追加しましたが、必要なだけ追加することができます。
スライドを追加したら、次のステップはコンテンツを挿入することです。 IronPPTは次のことを追加できます:
カスタムフォーマット: フォント、色、配置。
たとえば、スライドにタイトルを追加したり、画像を挿入したり、レイアウトのニーズに基づいて動的に位置を設定したりできます。 IronPPTのParagraphStyleおよびTextStyleクラスを使用して、スライドに追加されるテキストに書式設定やカスタムスタイルを適用できます。
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
TextBox textBox = new TextBox();
textBox.Type = ShapeType.Rectangle;
textBox.Width = 500;
textBox.Height = 200;
textBox.Position = (100, 100);
ppt.Slides[1].AddChild(textBox);
// Adding a styled paragraph to the second slide
var style = new ParagraphStyle()
{
Alignment = TextAlignmentTypeValues.Center,
NoBullet = true,
LineSpacing = 30,
ContextualSpacing = true,
};
TextStyle textStyle = new TextStyle()
{
IsBold = true,
Color = Color.Blue,
};
var paragraph = new Paragraph();
paragraph.Style = style;
paragraph.AddText("Let's create some awesome presentations with IronPPT!");
paragraph.TextStyle = textStyle;
ppt.Slides[1].TextBoxes[0].AddParagraph(paragraph);
ppt.Save("example.pptx");
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("test.pptx");
// Adding simple text to the title slide
ppt.Slides[0].TextBoxes[0].AddText("Welcome to IronPPT");
TextBox textBox = new TextBox();
textBox.Type = ShapeType.Rectangle;
textBox.Width = 500;
textBox.Height = 200;
textBox.Position = (100, 100);
ppt.Slides[1].AddChild(textBox);
// Adding a styled paragraph to the second slide
var style = new ParagraphStyle()
{
Alignment = TextAlignmentTypeValues.Center,
NoBullet = true,
LineSpacing = 30,
ContextualSpacing = true,
};
TextStyle textStyle = new TextStyle()
{
IsBold = true,
Color = Color.Blue,
};
var paragraph = new Paragraph();
paragraph.Style = style;
paragraph.AddText("Let's create some awesome presentations with IronPPT!");
paragraph.TextStyle = textStyle;
ppt.Slides[1].TextBoxes[0].AddParagraph(paragraph);
ppt.Save("example.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument("test.pptx")
' Adding simple text to the title slide
ppt.Slides(0).TextBoxes(0).AddText("Welcome to IronPPT")
Dim textBox As New TextBox()
textBox.Type = ShapeType.Rectangle
textBox.Width = 500
textBox.Height = 200
textBox.Position = (100, 100)
ppt.Slides(1).AddChild(textBox)
' Adding a styled paragraph to the second slide
Dim style = New ParagraphStyle() With {
.Alignment = TextAlignmentTypeValues.Center,
.NoBullet = True,
.LineSpacing = 30,
.ContextualSpacing = True
}
Dim textStyle As New TextStyle() With {
.IsBold = True,
.Color = Color.Blue
}
Dim paragraph As New Paragraph()
paragraph.Style = style
paragraph.AddText("Let's create some awesome presentations with IronPPT!")
paragraph.TextStyle = textStyle
ppt.Slides(1).TextBoxes(0).AddParagraph(paragraph)
ppt.Save("example.pptx")
出力
上記のコードでは、タイトル画面の既存のテキストボックスに新しいテキストを追加しました。 また、スタイル付き段落を追加する前に、2枚目のスライド用の新しいテキストボックスを作成しました。 これは、IronPPTを使用してPowerPointプレゼンテーションに完全にカスタマイズされたテキストを追加する方法のシンプルな例です。
次に、画像を追加して、タイトルスライドに配置し、スライド上に望むように配置するために、そのサイズと位置をカスタマイズしましょう。
using IronPPT;
using IronPPT.Models;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
ppt.Save("output.pptx");
using IronPPT;
using IronPPT.Models;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument();
Image image = new Image();
image.LoadFromFile("example.png");
var newImage = ppt.Slides[0].AddImage(image);
newImage.Position = (150, 300);
newImage.Name = "IronPPT";
newImage.Width = 450;
newImage.Height = 200;
ppt.Save("output.pptx");
Imports IronPPT
Imports IronPPT.Models
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument()
Private image As New Image()
image.LoadFromFile("example.png")
Dim newImage = ppt.Slides(0).AddImage(image)
newImage.Position = (150, 300)
newImage.Name = "IronPPT"
newImage.Width = 450
newImage.Height = 200
ppt.Save("output.pptx")
出力
シンプルなテキストや画像を超えて、PowerPointプレゼンテーションにはしばしば図形などの視覚的要素が含まれています。IronPPTを使用すると、図形を追加することもこれまでのテキストや画像の追加と同様に簡単に行えます。
例として、円形を作成し、指定されたスライドの特定の位置にそれを描画します。
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("example.pptx");
Shape shape = new Shape();
shape.Name = "Circle";
shape.Type = ShapeType.Ellipse;
shape.Width = 300;
shape.Height = 300;
shape.FillColor = Color.PowderBlue;
shape.OutlineColor = Color.Black;
shape.Position = (180, 200);
ppt.Slides[1].AddShape(shape);
ppt.Save("example.pptx");
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Creating a new PresentationDocument object
var ppt = new PresentationDocument("example.pptx");
Shape shape = new Shape();
shape.Name = "Circle";
shape.Type = ShapeType.Ellipse;
shape.Width = 300;
shape.Height = 300;
shape.FillColor = Color.PowderBlue;
shape.OutlineColor = Color.Black;
shape.Position = (180, 200);
ppt.Slides[1].AddShape(shape);
ppt.Save("example.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Creating a new PresentationDocument object
Private ppt = New PresentationDocument("example.pptx")
Private shape As New Shape()
shape.Name = "Circle"
shape.Type = ShapeType.Ellipse
shape.Width = 300
shape.Height = 300
shape.FillColor = Color.PowderBlue
shape.OutlineColor = Color.Black
shape.Position = (180, 200)
ppt.Slides(1).AddShape(shape)
ppt.Save("example.pptx")
出力
PowerPoint生成を自動化する際は、次のベストプラクティスを考慮してください:
エクスポートされたファイルが正しい形式と権限を持っていることを確認してください。
これらのベストプラクティスに従うことで、信頼性と効率性を確保しながら、高品質でプロフェッショナルなPowerPointプレゼンテーションを作成することができます。
C#でIronPPTを使用してPowerPoint作成を自動化することは、動的なプレゼンテーションを迅速かつ効率的に生成する必要がある開発者にとって革命的な手段です。 エンタープライズレポートシステム、教育ツール、またはビジネスダッシュボードを構築している場合でも、IronPPTを使用すると、.NETアプリケーション内でプログラムによってPowerPointファイルを作成および操作することが容易になります。
スライドのカスタマイズ、画像の挿入、PDFエクスポートなどの機能を備えたIronPPTは、スムーズなPowerPoint自動化に必要なすべてを提供します。
試してみますか? 無料トライアルをダウンロードし、今日からC#で自動化されたPowerPointプレゼンテーションの構築を始めましょう!