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()
{
    ShadowEffect = Shadow.OuterShadow1,
};

// 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("shadowEffect.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 {
    .ShadowEffect = Shadow.OuterShadow1
}

' 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("shadowEffect.docx")
NuGet Download
PM > Install-Package IronWord
新增陰影效果

新增陰影效果

實作文字的陰影效果

陰影效果透過在字元後面創造陰影偏移,為文字增加深度和層次。 IronWord 提供的 Shadow 類別中包含預設的陰影樣式,提供各種陰影風格,無需手動配置即可快速套用。

要新增陰影效果,請建立 TextStyle 並將其 TextEffect 屬性配置為如 Shadow.OuterShadow1 的陰影預設。 這些來自 Shadow 類別的靜態命名實例提供專業設計的陰影配置,具有適當的模糊、距離和角度設置。 外部陰影樣式將陰影投射到文字之外,建立一個抬升的外觀。

一旦文字風格配置了所需的陰影效果,建立一個包含 TextContentRun 物件,並將風格分配給 run。 使用 AddChild 將樣式化的 run 新增到 paragraph,然後將 paragraph 包含在 document 中。 這種方法遵循 IronWord 的 document 階層,確保陰影效果正確應用到輸出文件。

程式碼解析

僅需幾行程式碼就可在 Word 文件中的文字新增陰影效果。 為了完整性,首先初始化一個名為 doc 的新 WordDocument 實例。 然後,建立並配置一個 TextStyle 物件,通過將 Shadow.OuterShadow1 靜態命名實例分配給 TextEffect 屬性來整合陰影效果。

要新增帶有陰影效果的樣式文字,建立 Paragraph,然後建立一個包含 "Hello World" 的 Run 物件。 配置好的 textStyle 分配給 Run,應用陰影效果。 使用 AddChildRun 新增到 Paragraph,並將 Paragraph 新增到文件中。 這遵循文件階層:DocumentParagraphRunTextContent。 最後,導出 Word 文件。

如需更多範例和演示,請瀏覽以下文章:如何為文字新增陰影效果

探索 IronWord 教程中的文件元素。
在 GitHub 上查看

準備開始了嗎?

Nuget Downloads 56,401版本:2026.9剛剛發布

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