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()
{
    GradientEffect = Gradient.DefaultGray,
};

// 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("gradientEffect.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 {
    .GradientEffect = Gradient.DefaultGray
}

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

新增漸變效果

套用漸層效果於文字

IronWord中的漸層效果允許文字顯示顏色過渡,創造出視覺上吸引人的設計。 IronWord通過TextEffect

要套用漸層,請建立一個GradientEffect。 漸層可以使用來自Gradient類的預定義靜態實例設置,這些實例提供常用的顏色方案和過渡效果。 這些預設簡化了新增專業外觀漸層的過程,而無需手動配置顏色停止。

一旦樣式配置完成,請建立一個包含Style屬性。 使用AddChild將啟動新增到段落中,然後將段落插入文件。 這種結構化方法可確保漸層效果在輸出文件中得到正確應用和保留。

程式碼解析

上述程式碼演示了如何將漸層效果應用於文字。 首先,它建立了一個新的Word文件。 然後,它建立一個GradientEffect屬性來配置其使用漸層效果。

為了新增樣式化的文字,建立了一個Run物件,其中包含"Hello World"的TextContent。 經過配置的Run,應用了漸層效果。 Paragraph新增到文件中。 這遵循文件層級結構:Document → Paragraph → Run → TextContent。 最後,新的Word文件被匯出。

欲獲得更多範例和示範,請瀏覽以下文章:如何將漸層效果新增至文字

在此探索更多Word文件元素教程
在 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天試用金鑰
無需信用卡或帳戶建立