IRONSOFTWAREHOME

IronPPT 入門指南

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

IronPowerPoint:適用於 .NET 的 PowerPoint 函式庫

IronPPT 是由 Iron Software 開發的 PowerPoint 程式庫。 它在為 .NET 應用程式提供處理 PowerPoint 簡報的強大功能方面表現出色。

  • 載入、編輯及儲存 PowerPoint 簡報。 輕鬆處理 .pptx 和 .ppt 檔案。
  • SlideSetup:設定投影片大小、方向、背景顏色及版面配置。
  • 文字:處理文字內容、樣式、分割、追加文字以及新增文字方塊。
  • TextStyle:管理字型家族、大小、顏色、粗體、斜體、底線及對齊方式。
  • 圖形:新增及操作圖形,包括設定大小、位置、型別及旋轉角度。
  • 圖片:將圖片插入投影片,並提供縮放、對齊及定位選項。

安裝

IronPPT程式庫

安裝 IronPPT 既快速又簡單。 請使用以下方法新增套件:

PM > Install-Package IronPPT

您亦可直接從 IronPPT 官方 NuGet 網站下載。

安裝完成後,只需在 C# 程式碼頂端加入 using IronPPT; 即可開始使用。

套用授權金鑰

若要使用 IronPPT,請透過設定 LicenseKey 屬性來套用有效的授權金鑰或試用金鑰。 請在 import 語句之後、呼叫任何 IronPPT 方法之前,立即加入以下程式碼:

/// <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.");
        }
    }
}

程式碼範例

讓我們來探索一些程式碼範例及可用的功能。

建立 PowerPoint 檔案

透過使用 PresentationDocument 類別的其中一個建構子來建立 PowerPoint 簡報。 請分別使用 AddSlideAddText 方法來插入幻燈片和文字。 之後,請使用 Save 方法匯出 PowerPoint 簡報。

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");

新增圖形

您可以使用幻燈片物件中的 AddShape 方法來新增圖形。可設定各種圖形屬性,例如填充顏色、輪廓顏色、位置、角度、型別等。

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");

新增圖片

在任何投影片中加入圖片也是一項簡單的任務。 以下程式碼範例將圖片新增至第一張投影片,修改圖片的屬性(例如位置、角度、名稱、寬度和高度),然後將更新後的簡報儲存為 .pptx 檔案。

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");

提供授權與技術支援

IronPPT 為商業級程式庫,但提供免費試用授權

https://ironsoftware.com/如需瞭解 Iron Software 的更多詳情,請造訪我們的網站:。 若您需要支援或有任何疑問,請聯絡我們的團隊

Iron Software 技術支援

如需一般協助或技術諮詢,歡迎透過電子郵件聯絡我們:support@ironsoftware.com

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備好開始了嗎?

Nuget Downloads 6,070版本:2026.9剛剛發布

C# 用於 PDF 的 NuGet 程式庫
using NuGet 安裝

版本: 2026.9

PM > Install-Package IronPPT
nuget.org/packages/IronPPT/
  1. 在方案瀏覽器中,右鍵單擊引用,管理 NuGet 包
  2. 選擇瀏覽並搜索“IronPPT”
  3. 選擇包並安裝
C# PDF DLL
下載 DLL

版本: 2026.9

  1. 下載並解壓 IronPPT 至 ~/Libs 等目錄內的解決方案目錄中
  2. 在 Visual Studio 的解決方案資源管理器中,右鍵單擊引用。選擇瀏覽,“IronPPT.dll”

許可證從$999開始

有問題嗎?聯繫我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費實時演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software 的客戶標誌
獲取您的無義務諮詢
完成以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
受到全球數百萬工程師的信任
Iron Software 的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立