添加漸變效果 為文字套用漸層效果 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 文件元素教學 相關文檔連結 在 GitHub 上查看 相關教程 相關操作指南 類文檔 下載 IronWord DLL 回報此頁面的問題 準備好開始了嗎? Nuget 下載 36,374 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:36,374 查看許可證 還在捲動嗎? 想要快速證明? PM > Install-Package IronWord 執行範例 觀看您的資料變成 Word doc。 免費 NuGet 下載 總下載量:36,374 查看許可證