添加漸變效果

為文字套用漸層效果

IronWord 的漸層效果可讓文字呈現色彩過渡,創造出視覺上吸引人的設計。 IronWord provides preset gradient options through the Gradient class, such as Gradient.DefaultGray, which can be assigned directly to the GradientEffect property of a TextEffect.

To apply a gradient, create a TextStyle object and configure its TextEffect property with a GradientEffect. The gradient can be set using predefined static instances from the Gradient class, which offer commonly used color schemes and transitions. 這些預設值可簡化添加專業級漸層的流程,無需手動設定色彩停點。

Once the style is configured, create a Run containing TextContent and assign the style to the run's Style property. Add the run to a paragraph using AddChild, then insert the paragraph into the document. 這種結構化的方法可確保漸層效果在輸出文件中正確套用並完整保留。

程式碼說明

上述程式碼示範了如何為文字套用漸層效果。 首先,它會建立一個新的 WORD 文件。 Then, it creates a TextStyle object and configures it to use a gradient effect by assigning the Gradient.DefaultGray preset to the GradientEffect property.

To add the styled text, a Paragraph is created, then a Run object is created containing TextContent with "Hello World". The configured TextStyle is assigned to the Run, applying the gradient effect. The Run is added to the Paragraph using AddChild, and the Paragraph is added to the document. 此文件遵循以下層級結構:文件 → 段落 → 執行 → 文字內容。 最後,將新建立的 WORD 文件匯出。

如需更多範例與示範,請參閱以下文章:如何為文字添加漸變效果

在此探索更多 WORD 文件元素教學

準備開始了嗎?
Nuget 下載 44,829 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronWord
執行範例 觀看您的資料轉為 WORD 文件。