本文将介绍使用 Spire.Doc 在 C# 中实现该功能的简单代码。
渐变可用于 Word 背景以吸引眼球。在 MS Word 中,我们可以为渐变选择一种颜色或两种颜色,设置渐变的底纹样式和底纹变体。值得一提的是,Spire.Doc 支持在 C# 中使用上述所有选项设置渐变背景。本文将介绍使用 Spire.Doc 在 C# 中实现该功能的简单代码。
注意:开始之前,请下载最新版本的Spire.Doc,并将Spire.Doc.dll添加到bin文件夹中作为Visual Studio的参考。
第 1 步:加载只有文本的示例文档。
Document doc = new Document("Sample.docx");
第 2 步:将背景类型设置为渐变。
doc.Background.Type = BackgroundType.Gradient;BackgroundGradient Test =doc.Background.Gradient;
第 3 步:设置渐变的第一种颜色和第二种颜色。
Test.Color1 = Color.White;Test.Color2 = Color.Green;
第 4 步:设置渐变的阴影样式和变体。
Test.ShadingVariant = GradientShadingVariant.ShadingDown;Test.ShadingStyle = GradientShadingStyle.Horizontal;
第 5 步:保存文件并启动查看效果。
doc.SaveToFile("Result.docx", FileFormat.Docx);System.Diagnostics.Process.Start("Result.docx");
样品:
效果:
完整代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace ConsoleApplication1{class Program{static void Main(string[] args){Document doc = new Document("Sample.docx");doc.Background.Type = BackgroundType.Gradient;BackgroundGradient Test =doc.Background.Gradient;Test.Color1 = Color.White;Test.Color2 = Color.Green;Test.ShadingVariant = GradientShadingVariant.ShadingDown;Test.ShadingStyle = GradientShadingStyle.Horizontal;doc.SaveToFile("Result.docx", FileFormat.Docx);System.Diagnostics.Process.Start("Result.docx");}}}
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询在线客服 ;
标签:
来源:慧都
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!