IronPPTを使い始める

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

IronPowerPoint: .NET 用 PowerPoint ライブラリ

IronPPT は、Iron Software によって開発された PowerPoint ライブラリです。 .NET アプリケーションで PowerPoint プレゼンテーションを操作するための強力な機能を提供することに優れています。

  • PowerPoint プレゼンテーションを読み込み、操作し、保存します。 .pptx および .ppt ファイルを簡単に操作できます。
  • SlideSetup: スライドのサイズ、向き、背景色、レイアウトを構成します。
  • テキスト: テキストの内容、スタイル、分割、テキストの追加、テキスト ボックスの追加を処理します。
  • TextStyle: フォント ファミリ、サイズ、色、太字、斜体、下線、配置を管理します。
  • 図形: サイズ、位置、種類、回転の設定など、図形を追加および操作します。
  • 画像: 拡大縮小、配置、位置のオプションを使用して、スライドに画像を挿入します。

インストール

IronPPTライブラリ

IronPPT のインストールは迅速かつ簡単です。 次の方法でパッケージを追加します。

Install-Package IronPPT

あるいは、公式のIronPPT NuGet ウェブサイトから直接ダウンロードすることもできます。

インストール後、C# コードの先頭にusing IronPPT;を追加するだけで開始できます。

ライセンスキーの適用

IronPPT を使用するには、 LicenseKeyプロパティを設定して有効なライセンスまたは試用キーを適用します。 インポート ステートメントの直後、IronPPT メソッドを呼び出す前に次のコードを追加します。

:path=/static-assets/ppt/content-code-examples/get-started/get-started-license.cs
/// <summary>
/// This code sets the license key for the IronPPT library.
/// Ensure you have the correct namespace access by installing the IronPPT NuGet package
/// and adjust the license key appropriately for your use case.
/// </summary>

using System; // Required for Console output
using IronPPT; // Ensure the IronPPT library is referenced in your project.

namespace IronPPTApplication
{
    class Program
    {
        public static void Main(string[] args)
        {
            // Calling the method to set the IronPPT license key.
            SetIronPPTLicense();
        }

        /// <summary>
        /// Sets the license key for the IronPPT library to unlock its full features.
        /// </summary>
        private static void SetIronPPTLicense()
        {
            // Correctly setting the license for the IronPPT library.
            // Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
            IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01";

            // Inform the user that the license key has been set.
            Console.WriteLine("IronPPT license key has been set.");
        }
    }
}
''' <summary>
''' This code sets the license key for the IronPPT library.
''' Ensure you have the correct namespace access by installing the IronPPT NuGet package
''' and adjust the license key appropriately for your use case.
''' </summary>

Imports System ' Required for Console output
Imports IronPPT ' Ensure the IronPPT library is referenced in your project.

Namespace IronPPTApplication
	Friend Class Program
		Public Shared Sub Main(ByVal args() As String)
			' Calling the method to set the IronPPT license key.
			SetIronPPTLicense()
		End Sub

		''' <summary>
		''' Sets the license key for the IronPPT library to unlock its full features.
		''' </summary>
		Private Shared Sub SetIronPPTLicense()
			' Correctly setting the license for the IronPPT library.
			' Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
			IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01"

			' Inform the user that the license key has been set.
			Console.WriteLine("IronPPT license key has been set.")
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

コード例

いくつかのコード例と利用可能な機能を探りましょう。

PowerPointファイルを作成する

コンストラクターの 1 つを使用してPresentationDocumentクラスをインスタンス化し、PowerPoint プレゼンテーションを作成します。 スライドとテキストを追加するには、それぞれAddSlideAddTextメソッドを使用します。 その後、 Saveメソッドを使用して PowerPoint プレゼンテーションをエクスポートします。

:path=/static-assets/ppt/content-code-examples/get-started/get-started-1.cs
using IronPPT;

// This code demonstrates the creation of a PowerPoint presentation and saving it as a file.

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

// Create a new slide object
var slide = new Slide();

// Add text content to the slide
slide.AddText("Hello!");

// Add the newly created slide with text to the document
document.AddSlide(slide);

// Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx");
Imports IronPPT

' This code demonstrates the creation of a PowerPoint presentation and saving it as a file.

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

' Create a new slide object
Private slide = New Slide()

' Add text content to the slide
slide.AddText("Hello!")

' Add the newly created slide with text to the document
document.AddSlide(slide)

' Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx")
$vbLabelText   $csharpLabel

図形を追加

スライドオブジェクトのAddShapeメソッドを使用して図形を追加できます。塗りつぶしの色、アウトラインの色、位置、角度、種類など、図形のさまざまなプロパティを設定できます。

:path=/static-assets/ppt/content-code-examples/get-started/get-started-2.cs
using IronPPT;
using IronPPT.Drawing; // Assuming this namespace contains `Shape` and `Color` classes
using IronPPT.Enums; // Assuming this namespace contains the `ShapeType` enum

// Load a PowerPoint presentation from the specified file
var document = new PresentationDocument("output.pptx");

// Create and configure a new shape, in this case, a triangle
Shape shape = new Shape
{
    Name = "triangle",             // Assign a name to the shape
    Type = ShapeType.Triangle,     // Set the shape type to Triangle
    Width = 100,                   // Set the width of the shape
    Height = 100,                  // Assumed height for the shape, should be set for visibility
    FillColor = new Color("#444444"), // Set the fill color of the shape
    OutlineColor = Color.Black,    // Set the outline color to black
    Position = new System.Drawing.Point(200, 200) // Set the position of the shape
};

// Ensure that the slides array has at least one slide to add the shape to
if (document.Slides.Count > 0)
{
    // Add the shape to the first slide
    document.Slides[0].AddShape(shape);
}
else
{
    // If there are no slides, handle the error or add a slide
    document.Slides.Add(new Slide()); // Assuming there's a way to add new slides
    document.Slides[0].AddShape(shape); // Add the shape to the newly added slide
}

// Export the PowerPoint presentation to a new file
document.Save("addShape.pptx");
Imports IronPPT
Imports IronPPT.Drawing ' Assuming this namespace contains `Shape` and `Color` classes
Imports IronPPT.Enums ' Assuming this namespace contains the `ShapeType` enum

' Load a PowerPoint presentation from the specified file
Private document = New PresentationDocument("output.pptx")

' Create and configure a new shape, in this case, a triangle
Private shape As New Shape With {
	.Name = "triangle",
	.Type = ShapeType.Triangle,
	.Width = 100,
	.Height = 100,
	.FillColor = New Color("#444444"),
	.OutlineColor = Color.Black,
	.Position = New System.Drawing.Point(200, 200)
}

' Ensure that the slides array has at least one slide to add the shape to
If document.Slides.Count > 0 Then
	' Add the shape to the first slide
	document.Slides(0).AddShape(shape)
Else
	' If there are no slides, handle the error or add a slide
	document.Slides.Add(New Slide()) ' Assuming there's a way to add new slides
	document.Slides(0).AddShape(shape) ' Add the shape to the newly added slide
End If

' Export the PowerPoint presentation to a new file
document.Save("addShape.pptx")
$vbLabelText   $csharpLabel

画像の追加

スライドに画像を追加することも簡単な作業です。 以下のコード例では、最初のスライドに画像を追加し、位置、角度、名前、幅、高さなどの画像のプロパティを変更し、更新されたプレゼンテーションを .pptx ファイルとして保存します。

:path=/static-assets/ppt/content-code-examples/get-started/get-started-3.cs
using IronPPT;
using System.Drawing;

// This code demonstrates creating a new PowerPoint presentation, adding an image to it,
// modifying the image's properties, and exporting the presentation.

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

// Ensure there's at least one slide in the presentation
// Create the first slide if it doesn't exist yet
if (document.Slides.Count == 0)
{
    document.Slides.Add();
}

// Initialize an Image object
// Load an image from a file specified by the file path
// Ensure that "sample.png" exists at the specified path
Image image = new Image(); 
image.LoadFromFile("sample.png");

// Add the image to the first slide of the presentation
var newImage = document.Slides[0].AddImage(image);

// Edit the image's properties
// Set the position of the image using X and Y coordinates
newImage.Position = new Point(200, 200);

// Set the rotation angle of the image in degrees
newImage.Angle = 45;

// Set a name for the image, which can be useful for identification
newImage.Name = "new image";

// Set the dimensions of the image
newImage.Width = 150;
newImage.Height = 150;

// Export the PowerPoint presentation with the new image
document.Save("addImage.pptx");
Imports IronPPT
Imports System.Drawing

' This code demonstrates creating a new PowerPoint presentation, adding an image to it,
' modifying the image's properties, and exporting the presentation.

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

' Ensure there's at least one slide in the presentation
' Create the first slide if it doesn't exist yet
If document.Slides.Count = 0 Then
	document.Slides.Add()
End If

' Initialize an Image object
' Load an image from a file specified by the file path
' Ensure that "sample.png" exists at the specified path
Dim image As New Image()
image.LoadFromFile("sample.png")

' Add the image to the first slide of the presentation
Dim newImage = document.Slides(0).AddImage(image)

' Edit the image's properties
' Set the position of the image using X and Y coordinates
newImage.Position = New Point(200, 200)

' Set the rotation angle of the image in degrees
newImage.Angle = 45

' Set a name for the image, which can be useful for identification
newImage.Name = "new image"

' Set the dimensions of the image
newImage.Width = 150
newImage.Height = 150

' Export the PowerPoint presentation with the new image
document.Save("addImage.pptx")
$vbLabelText   $csharpLabel

ライセンスとサポートの提供

IronPPTは商用ライブラリですが、無料の試用ライセンスも利用可能です。

Iron Software の詳細については、次の Web サイトをご覧ください。https://ironsoftware.com/ 。 サポートが必要な場合やご質問がある場合は、当社のチームにお問い合わせください。

アイアンソフトウェアサポート

一般的なサポートや技術的な質問については、お気軽に以下のメールアドレスまでお問い合わせください。support@ironsoftware.com

カーティス・チャウ
テクニカルライター

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

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

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