IronWord 操作指南 文本上的漸層效果 How to Add Gradient Effect to Text Curtis Chau 更新日期:6月 9, 2025 Download IronWord NuGet 下載 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English A gradient effect on text involves applying a smooth transition of colors across the characters or background of text, creating a blend from one color to another or multiple colors. This effect adds depth, visual interest, and a dynamic appearance to the text, making it stand out and enhancing its aesthetic appearance. Gradient effects can be linear (colors transition in a straight line) or radial (colors transition from a central point outward). Quickstart: Add a Gradient Effect to Text with IronWord Here’s a simple example showing how to use IronWord to apply a built-in gradient effect to text in just a few lines—perfect if you want to get started quickly and see visual results instantly. Get started making PDFs with NuGet now: Install IronWord with NuGet Package Manager PM > Install-Package IronWord Copy and run this code snippet. var doc = new IronWord.WordDocument(); doc.AddText("Test").Style = new IronWord.Models.TextStyle(){ TextEffect = new IronWord.Models.TextEffect(){ GradientEffect = IronWord.Models.Gradient.DefaultGray } }; doc.SaveAs("out.docx"); Deploy to test on your live environment Start using IronWord in your project today with a free trial Free 30 day Trial Minimal Workflow (5 steps) Download a C# library that enables adding gradients to text. Apply the text effect to either newly created or existing text. Use a preset gradient effect by using the static named instance of the Gradient class. Configure the GradientEffect properties to customize the text outline. Export the edited Word document as a new file. Add Gradient Effect To specify the gradient effect for the text, create the TextStyle object and populate the GradientEffect property with a Gradient object. Finally, add new text with the style by assigning the TextStyle object to the TextEffect property. :path=/static-assets/word/content-code-examples/how-to/text-effect-gradient-effect.cs 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, }; // Add text with style doc.AddText("Hello World").Style = textStyle; // Export new Word document doc.SaveAs("gradientEffect.docx"); Imports IronWord Imports IronWord.Models ' Create new Word document Private doc As New WordDocument() ' Create and configure text style Private textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With {.GradientEffect = Gradient.DefaultGray} ' Add text with style doc.AddText("Hello World").Style = textStyle ' Export new Word document doc.SaveAs("gradientEffect.docx") $vbLabelText $csharpLabel Gradient Effect Properties The gradient effect provides a range of adjustable attributes to meet diverse design requirements. See the following list for detailed descriptions of each property: GradientStop Color: Gets or sets the scheme color of the gradient stop. StopPoint: Gets or sets the position of the gradient stop. Gradient stops are points within a gradient where a specific color is defined. Gradient StopPoints: Gets or sets the list of gradient stops defining the gradient fill. LinearShadeScaled: Gets or sets a value indicating whether the linear shade is scaled. LinearShadeAngle: Gets or sets the angle of the linear shade. :path=/static-assets/word/content-code-examples/how-to/text-effect-customized-gradient-effect.cs using IronWord; using IronWord.Models; using System.Collections.Generic; // Create new Word document WordDocument doc = new WordDocument(); // Create gradient stops GradientStop firstGradientStop = new GradientStop() { Color = IronWord.Models.Color.Aqua, StopPoint = 1 }; GradientStop secondGradientStop = new GradientStop() { Color = IronWord.Models.Color.OrangeRed, StopPoint = 10 }; // Create and configure text style TextStyle textStyle = new TextStyle(); textStyle.TextEffect = new TextEffect() { GradientEffect = new Gradient() { StopPoints = new List<GradientStop> { firstGradientStop, secondGradientStop }, LinearShadeAngle = 45, LinearShadeScaled = true, } }; // Add text with style doc.AddText("Hello World").Style = textStyle; // Export new Word document doc.SaveAs("customizedGradientEffect.docx"); Imports IronWord Imports IronWord.Models Imports System.Collections.Generic ' Create new Word document Private doc As New WordDocument() ' Create gradient stops Private firstGradientStop As New GradientStop() With { .Color = IronWord.Models.Color.Aqua, .StopPoint = 1 } Private secondGradientStop As New GradientStop() With { .Color = IronWord.Models.Color.OrangeRed, .StopPoint = 10 } ' Create and configure text style Private textStyle As New TextStyle() textStyle.TextEffect = New TextEffect() With { .GradientEffect = New Gradient() With { .StopPoints = New List(Of GradientStop) From {firstGradientStop, secondGradientStop}, .LinearShadeAngle = 45, .LinearShadeScaled = True } } ' Add text with style doc.AddText("Hello World").Style = textStyle ' Export new Word document doc.SaveAs("customizedGradientEffect.docx") $vbLabelText $csharpLabel 常見問題解答 如何使用 C# 在 Word 文件中添加漸層效果到文本? 您可以使用 IronWord 的 C# 庫在 Word 文件中為文本添加漸層效果。首先,下載庫,然後將文本效果應用於新文本或現有文本。通過 Gradient 類的靜態命名實例使用預設的漸層效果,並通過配置 GradientEffect 屬性進行自定義。 使用 IronWord 應用漸層效果的步驟是什麼? 要使用 IronWord 應用漸層效果,請按照以下步驟進行:下載 C# 庫,將漸層應用於文本,使用 Gradient 類中的預設漸層效果,配置 GradientEffect 屬性,然後,導出編輯的文件。 如何在 IronWord 中創建帶有漸層效果的 TextStyle 對象? 在 IronWord 中,創建一個 TextStyle 對象,並用一個 Gradient 對象填充 GradientEffect 屬性。將此 TextStyle 賦予 TextEffect 屬性,以將其應用於您的文本。 IronWord 中漸層停點的用途是什麼? IronWord 中的漸層停點是漸層內指定顏色的點。它們由 GradientStop 類控制,其中包括 Color 的方案顏色和 StopPoint 的漸層點位置等屬性。 IronWord 中的漸層停點可以自定義嗎? 是的,您可以在 IronWord 中自定義漸層停點,方法是向 Gradient 對象的 StopPoints 列表添加具有特定顏色和位置的 GradientStop 對象,從而實現個人化的漸層效果。 IronWord 中 Gradient 類的主要屬性有哪些? IronWord 中的 Gradient 類包含關鍵屬性,例如 StopPoints 定義漸層停點,LinearShadeScaled 指示線性陰影是否縮放,以及 LinearShadeAngle 設定線性陰影的角度。 使用 IronWord 添加漸層效果後如何導出 Word 文件? 使用 IronWord 為文本添加漸層效果後,您可以通過將其保存為應用漸層效果的所需格式的新文件來導出編輯的 Word 文件。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 25,807 | 版本: 2025.11 剛剛發布 免費 NuGet 下載 總下載量:25,807 查看許可證