IRONSOFTWAREHOME

C# Slide Element Tutorial – IronPPT

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

IronPPT 是一款功能強大的 PowerPoint 程式庫,旨在協助 .NET C# 開發人員將建立、讀取及編輯 PowerPoint 簡報的功能無縫整合至其應用程式中。 在 PowerPoint 簡報的語境中,投影片是結構化與組織內容的基礎元素。

快速入門:將文字插入新投影片或現有投影片

此範例展示了您如何輕鬆地使用 IronPPT 在投影片中加入文字。 只需幾行程式碼,若已有第一張投影片則插入其中,否則直接建立一張,然後節省設定時間,省時省力。

  1. 1Install IronPPT with NuGet Package Manager

    PM > Install-Package IronPPT

  2. 2複製並運行這段程式碼片段。

    var doc = new IronPPT.PresentationDocument();
    var text = doc.Slides.Count > 0 ? doc.Slides[0].AddText("Quick Option") : doc.Slides.Add(new IronPPT.Models.Slide()).AddText("Quick Option");
    doc.Save("quick.pptx");
    C#
  3. 3部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronPPT,透過免費試用
    arrow pointer

目錄

新增文字

文字內容

無論您是製作新的簡報,還是編輯現有的簡報,文字管理工具都能讓您完全掌控文字的排版與格式,讓您設計出能清晰且Professional地傳達訊息的投影片。

using IronPPT;
using IronPPT.Models;

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

// Ensure there is at least one slide to work with
if (document.Slides.Count == 0)
{
    document.Slides.Add(new Slide());
}

// Add text to the first slide
var text = document.Slides[0].AddText("Hello");

// Append text to the existing text on the slide
text.Text += " There!";

// Check if there is any text element to remove from the first slide
if (document.Slides[0].Texts.Count > 0)
{
    document.Slides[0].Texts[0].Remove();
}

// Export the PowerPoint presentation with the specified file name
document.Save("addText.pptx");
C#

設定樣式

透過文字樣式設定,您可以透過定義字型大小、顏色、樣式、刪除線和底線等屬性,自訂文字的外觀。套用這些樣式可提升文字的呈現效果,並改善文件的整體視覺效果。

using IronPPT;
using IronPPT.Models; // Ensure the library is available
using IronPPT.Enums;

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

// Define and customize the text style
var textStyle = new TextStyle
{
    IsBold = true,                      // Text is bold
    IsItalic = true,                    // Text is italic
    Color = Color.Blue,                 // Text color is blue
    Strike = StrikValue.SingleStrike,   // Text is single struck-off
    Outline = true,                     // Text has an outline
    NoProof = true,                     // Disables proofing for the text
    Spacing = 10.0,                     // Text spacing is set to 10
    Underline = new Underline 
    {
        LineValue = UnderlineValues.Single,   // Single underline
        Color = Color.Red                     // Underline color is red
    },
    Languages = "en-US",               // Text language is set to U.S. English
    SpecVanish = false,                // Text does not vanish when special formatting is applied
};

// Create text content and apply the defined style
var text = new Text("Hello World");   // Instantiate text with a string
text.TextStyle = textStyle;           // Apply the defined style to the text

// Add a new slide if none exist
if (document.Slides.Count == 0)
{
    document.Slides.Add(new Slide());   // Add a new slide to the document
}

// Add the styled text to the first slide
document.Slides[0].AddText(text);      // Add the newly created text object to the first slide

// Save the presentation document to a file
document.Save("textStyle.pptx");        // Save the document with the filename "textStyle.pptx"
C#

新增圖片

請調整圖片設定以獲得最佳顯示效果。 正確的配置可確保圖片視覺上美觀且與上下文相符。

using IronPPT;
using IronPPT.Models;
using System.Drawing;

// This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
// An image is added to the presentation, its properties are modified, and then the presentation is saved.

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

// Create a new Image object and load an image file.
var image = new Image();
image.LoadFromFile("sample.png");

// Add the image to the first slide (index 0) of the presentation.
var newImage = document.AddImage(image, 0);

// Set the properties of the added image.
// Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = new Point(200, 200); // Set image position on the slide
newImage.Angle = 45; // Set the rotation angle of the image
newImage.Name = "new image"; // Assign a descriptive name to the image
newImage.Width = 150; // Set the width of the image in pixels
newImage.Height = 150; // Set the height of the image in pixels

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

新增圖形

透過定義形狀的型別、尺寸(寬度和高度)、內填色與輪廓色,以及在投影片上的位置,即可輕鬆在簡報中新增並自訂形狀。

using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;

// Load a PowerPoint presentation.
// The PresentationDocument is assumed to represent an entire PPTX file loaded from disk.
var document = new PresentationDocument("output.pptx");

// Configure a new shape.
// Shape is assumed to be a model object representing drawable elements on a slide.
Shape shape = new Shape
{
    Name = "triangle",
    Type = ShapeType.Triangle,
    Width = 100,
    Height = 100,
    FillColor = new Color("#444444"),
    OutlineColor = Color.Black,

    // Position is set via the Position property, which accepts an (x, y) tuple.
    // It's important that these coordinates are valid for display on the slide.
    Position = (200, 200)
};

// Add the shape to the first slide in the presentation.
// Slides[0] refers to the first slide in the collection. Ensure a slide exists at this index.
document.Slides[0].AddShape(shape);

// Export the modified PowerPoint presentation.
// Saves the changes to a new file, ensuring the original presentation is not overwritten.
document.Save("addShape.pptx");
C#

常見問題

IronPPT 用於什麼?

IronPPT 是一個為 .NET C# 開發者設計的全面 PowerPoint 程式庫,讓他們能夠無縫地在應用程式中建立、讀取和編輯 PowerPoint 演示。

如何使用 IronPPT 新增文字到幻燈片?

要使用 IronPPT 將文字新增到幻燈片,只需使用幾行程式碼即可將文字插入到現有幻燈片或建立一個新幻燈片,然後保存演示。

我可以在 IronPPT 中自定義文字樣式嗎?

是的,IronPPT 允許您自定義文字樣式,通過定義字體大小、顏色、樣式、刪除線和底線等屬性來增強文字的外觀。

如何使用 IronPPT 將圖像新增到 PowerPoint 演示中?

IronPPT 提供工具來從檔案或 FileStreams 載入圖像,並配置其尺寸、角度和位置,以確保您的演示中顯示最佳效果。

在 IronPPT 中可以新增形狀嗎?

是的,您可以在 IronPPT 中新增和自定義形狀,通過設置其型別、尺寸、填充和輪廓顏色,以及在幻燈片上的位置。

IronPPT 是否支持編輯現有的 PowerPoint 演示?

IronPPT 允許您建立新演示和編輯現有的演示,使您能夠完全控制內容和格式。

我可以在 IronPPT 中設置文字和圖像的位置嗎?

是的,IronPPT 允許您設置幻燈片上文字和圖像的位置,允許精確放置以適合您的演示佈局。

IronPPT 支持哪些影像格式的插入?

IronPPT 支持從各種檔案格式插入影像,確保您的演示的視覺資產的相容性。

IronPPT 如何增強演示的視覺吸引力?

IronPPT 透過提供自定義文字樣式、影像配置和形狀設計的工具來增強視覺吸引力,確保專業的演示外觀。

IronPPT 是否相容不同版本的 PowerPoint?

IronPPT 被設計為相容各種版本的 PowerPoint,允許無縫整合到您的 C# 應用程式中。

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天試用金鑰
無需信用卡或帳戶建立