IRONSOFTWAREHOME
新增文字大綱
using IronWord;
using IronWord.Models;

// Create new Word document
WordDocument doc = new WordDocument();

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    TextOutlineEffect = TextOutlineEffect.DefaultEffect,
};

// Create paragraph
Paragraph paragraph = new Paragraph();

// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;

// Add run to paragraph
paragraph.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Export new Word document
doc.SaveAs("textOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Dim doc As New WordDocument()

' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
    .TextOutlineEffect = TextOutlineEffect.DefaultEffect
}

' Create paragraph
Dim paragraph As New Paragraph()

' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle

' Add run to paragraph
paragraph.AddChild(textRun)

' Add paragraph to document
doc.AddParagraph(paragraph)

' Export new Word document
doc.SaveAs("textOutlineEffect.docx")
NuGet Download
PM > Install-Package IronWord
新增文字大綱

新增文字大綱

新增文字輪廓效果

文字輪廓效果透過在每個字元周圍繪製邊框來增強文字的可視性和風格。 此效果對於建立粗體、引人注目的文字或在文字出現於圖像或彩色背景上時確保可讀性特別有用。 IronWord 提供 TextOutlineEffect 類,具有預設配置以快速實現。

要應用文字輪廓,需建立一個 TextStyle 物件,並使用 TextOutlineEffect.DefaultEffect 配置其 TextEffect 屬性。 此預設提供標準輪廓配置,適用於大多數場景。 對於自訂輪廓,開發者可以指定諸如輪廓寬度、顏色和線條樣式的屬性來達成特定的視覺效果。

設定完文字樣式後,建立一個包含所需 TextContent 的 Run,並將配置的樣式賦予到執行的 Style 屬性。 使用 AddChild 將已設計的執行加入段落,再將段落加到文件中。 這種結構性的方法確保了正確的格式化並維持文件的完整性。

程式碼解析

using IronWord,對文字應用輪廓超級簡單。 儘管其簡單性,文字輪廓的每個屬性皆可調整以符合各種需求。 一旦Word文件被匯入,通過將 TextOutlineEffect.DefaultEffect 指派給新 TextEffect 實例的 TextOutlineEffect 屬性來配置 textStyle 以包含文字輪廓效果。

要將此效果應用於文字,需先建立一個 Paragraph,然後建立一個包含所需 TextContent 的 Run 物件。 配置的 textStyle 被指派給 Run,應用了文字輪廓效果。 Run 使用 AddChild 加入到 Paragraph 中,並將 Paragraph 加到文件。 這遵循文件層級結構:Document → Paragraph → Run → TextContent。 最後,文件被導出。

了解更多有關使用 IronWord 的文件元素。
在 GitHub 上查看

準備開始了嗎?

Nuget Downloads 57,266版本:2026.9剛剛發布

Key in blue circle

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

Your trial license will be sent to your email address

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

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

全球數百萬工程師信賴

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