添加渐变效果 将渐变效果应用于文本 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 下载 35,581 | 版本: 2026.3 刚刚发布 免费试用 免费 NuGet 下载 总下载量:35,581 查看许可证 还在滚动吗? 想快速获得证据? PM > Install-Package IronWord 运行示例 观看您的数据变成 Word 文档。 免费 NuGet 下载 总下载量:35,581 查看许可证