IRONSOFTWAREHOME
添加渐变效果
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,
};

// Create paragraph
Paragraph paragraph = new Paragraph();

// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;

// Add run to paragraph
paragraph.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Export new Word document
doc.SaveAs("gradientEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Dim doc As New WordDocument()

' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
    .GradientEffect = Gradient.DefaultGray
}

' Create paragraph
Dim paragraph As New Paragraph()

' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle

' Add run to paragraph
paragraph.AddChild(textRun)

' Add paragraph to document
doc.AddParagraph(paragraph)

' Export new Word document
doc.SaveAs("gradientEffect.docx")
NuGet Download
PM > Install-Package IronWord
添加渐变效果

添加渐变效果

将渐变效果应用于文本

IronWord中的渐变效果可以让文本显示颜色过渡,从而创造出视觉上吸引人的设计。 IronWord通过GradientEffect属性。

要应用渐变,创建一个TextEffect属性。 可以使用Gradient类中的预定义静态实例设置渐变,这些实例提供常用的配色方案和过渡。 这些预设简化了添加专业级渐变效果的过程,无需手动配置颜色停止点。

一旦样式配置完成,创建一个包含Style属性。 使用AddChild将运行添加到段落中,然后将段落插入到文档中。 这种结构化的方法确保渐变效果能够正确应用并保留在输出文档中。

代码解释

以上代码演示了如何为文本应用渐变效果。 首先,它会创建一个新的 Word 文档。 然后,它创建一个GradientEffect属性来配置它以使用渐变效果。

为了添加样式化文本,创建一个Run对象,并包含"Hello World"。 配置好的Run,应用渐变效果。 使用Paragraph添加到文档中。 这遵循文档层次结构:文档 → 段落 → 运行 → 文本内容。 最后,新的 Word 文档导出完成。

更多示例和演示,请参阅以下文章:如何为文本添加渐变效果

点击此处查看更多 Word 文档元素教程
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 56,401版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户