IronWord 如何使用 文字上的漸層效果 如何在 C# 中加入漸層文字效果 Curtis Chau 更新:6月 9, 2025 下載 IronWord NuGet 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English 文字漸變效果是指在文字字元或背景上套用平滑的顏色過渡,從而創造從一種顏色到另一種顏色或多種顏色的混合效果。 這種效果為文字增添了深度、視覺趣味和動態外觀,使其脫穎而出,增強了其美感。 漸變效果可以是線性的(顏色沿直線過渡)或徑向的(顏色從中心點向外過渡)。 快速入門:使用 IronWord 為文字加上漸層效果 這裡有一個簡單的範例,展示如何使用 IronWord 在幾行程式碼中將內建的漸變效果應用於文字——如果您想快速上手並立即看到視覺效果,這將是完美的選擇。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronWord PM > Install-Package IronWord 複製並運行這段程式碼。 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"); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronWord,免費試用! 免費試用30天 最小工作流程(5 個步驟) 下載一個可以為文字新增漸層效果的 C# 函式庫。 將文字效果套用至新建文字或現有文字。 使用Gradient類別的靜態命名實例,即可使用預設的漸層效果。 配置GradientEffect屬性以自訂文字輪廓。 將編輯後的 Word 文件匯出為新文件。 增加漸變效果 若要指定文字的漸層效果,請建立TextStyle對象,並使用Gradient物件填入 GradientEffect 屬性。 最後,透過將TextStyle物件指派給 TextEffect 屬性來新增具有該樣式的新文字。 :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 梯度效應特性 漸變效果提供了一系列可調節屬性,以滿足不同的設計需求。 以下列表詳細介紹了每個房產: 漸變停止 -顏色:取得或設定漸層停止點的方案顏色。 StopPoint :取得或設定漸變停止點的位置。 漸變停止點是指漸層中定義特定顏色的點。 Gradient StopPoints :取得或設定定義漸層填滿的漸層停止點清單。 LinearShadeScaled :取得或設定一個值,該值指示線性陰影是否縮放。 LinearShadeAngle :取得或設定線性遮光簾的角度。 :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 下載 27,129 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:27,129 檢視授權