Word是我们日常生活、学习和工作中必不可少的文档处理工具。精致美观的文档能给人带来阅读时视觉上的美感。在本篇文章中,将介绍如何使用组件Free Spire.Doc for .NET(社区版)给Word设置文档背景。下面的示例中,给Word添加背景分为三种情况来讲述,即添加纯色背景,渐变色背景和图片背景。
工具使用:下载安装控件Free Spire.Doc后,在项目程序中添加Spire.Doc.dll即可(该dll可在安装文件下Bin文件夹中获取)
一、添加纯色背景using Spire.Doc;using System.Drawing;namespace AddBackground{ class Program { static voID Main(string[] args) { //创建一个document类对象,并加载Word文档 document document = new document(); document.LoadFromfile(@"C:\Users\administrator\Desktop\Test.docx"); //设置文档的背景填充模式为颜色填充 document.Background.Type = Spire.Doc.documents.BackgroundType.color; //设置背景颜色 document.Background.color = color.MistyRose; //保存并打开文档 document.Savetofile("PureBackground.docx",fileFormat.Docx2013); System.Diagnostics.Process.Start("PureBackground.docx"); } }}
调试运行程序后,生成文档
二、添加渐变色背景using Spire.Doc;using System.Drawing;using Spire.Doc.documents;namespace AddGradIEntBackground{ class Program { static voID Main(string[] args) { //创建document类实例,并加载Word文档 document document = new document(); document.LoadFromfile(@"C:\Users\administrator\Desktop\Test.docx"); //设置文档的背景填充模式为渐变填充 document.Background.Type = Spire.Doc.documents.BackgroundType.GradIEnt; //设置渐变背景颜色 BackgroundGradIEnt gradIEnt = document.Background.GradIEnt; gradIEnt.color1 = color.lightSkyBlue; gradIEnt.color2 = color.PaleGreen; //设置渐变模式 gradIEnt.ShadingVariant = GradIEntShadingVariant.ShadingMIDdle; gradIEnt.ShadingStyle = GradIEntShadingStyle.FromCenter; //保存并打开文档 document.Savetofile("GradIEntcolor.docx",fileFormat.Docx2013); System.Diagnostics.Process.Start("GradIEntcolor.docx"); } }}三、添加图片背景
using System.Drawing;using Spire.Doc;namespace imagebackground{ class Program { static voID Main(string[] args) { //创建一个document类实例,并加载Word文档 document document = new document(); document.LoadFromfile(@"C:\Users\administrator\Desktop\Test.docx"); //设置文档的背景填充模式为图片填充 document.Background.Type = Spire.Doc.documents.BackgroundType.Picture; //设置背景图片 document.Background.Picture = Image.Fromfile(@"C:\Users\administrator\Desktop.jpg"); //保存并打开文档 document.Savetofile("imagebackground.docx",fileFormat.Docx2013); System.Diagnostics.Process.Start("imagebackground.docx"); } }}
总结
以上所述是小编给大家介绍的C#设置Word文档背景的三种方法(纯色/渐变/图片背景),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
您可能感兴趣的文章:C#对Word文档的创建、插入表格、设置样式等 *** 作实例C# 向Word中设置/更改文本方向的方法(两种)C#添加、读取Word脚注尾注的方法C# WORD *** 作实现代码C#实现通过模板自动创建Word文档的方法C# Word 类库的深入理解比较全的一个C# *** 作word文档示例C# 利用Aspose.Words.dll将 Word 转成PDFasp.net(c#)下读取word文档的方法小结C#如何更改Word的语言设置 总结以上是内存溢出为你收集整理的C#设置Word文档背景的三种方法(纯色/渐变/图片背景)全部内容,希望文章能够帮你解决C#设置Word文档背景的三种方法(纯色/渐变/图片背景)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)