C # manipulating Word documents--how to set the Word document background

Source: Internet
Author: User

Word is an essential document processing tool in our daily life, learning and work. Delicate and beautiful documents can be visually pleasing in reading. In this article, you will learn how to use the component free Spire.doc for. NET (Community Edition) sets the document background for Word. In the following example, adding a background to word is described in three scenarios: adding a solid background, gradient background, and picture background.
Tool Use:After downloading the install control free Spire.doc, add Spire.Doc.dll in the project program (the DLL can be obtained in the Bin folder under the installation file)

First, add a solid color background

C#

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");        }    }}

After you debug the run program, generate the document

Second, add gradient background

C#

  using spire.doc;using system.drawing;using spire.doc.documents;namespace addgradientbackground{class program {static void Main (string[] args) {//Create a document class object and load Word documents            Cument = new Document (); Document.            LoadFromFile (@ "C:\Users\Administrator\Desktop\Test.docx"); Sets the background fill mode for the document to fill the file with a gradient.            Background.type = Spire.Doc.Documents.BackgroundType.Gradient; Sets the gradient background color backgroundgradient gradient = document.            Background.gradient; Gradient.            Color1 = Color.lightskyblue; Gradient.            Color2 = Color.palegreen; Sets the gradient mode gradient.            Shadingvariant = Gradientshadingvariant.shadingmiddle; Gradient.            Shadingstyle = Gradientshadingstyle.fromcenter; Save and open documents document.            SaveToFile ("Gradientcolor.docx", fileformat.docx2013);        System.Diagnostics.Process.Start ("Gradientcolor.docx"); }    }}

Third, add picture background

C#

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\1.jpg");            //保存并打开文档            document.SaveToFile("ImageBackground.docx", FileFormat.Docx2013);            System.Diagnostics.Process.Start("ImageBackground.docx");        }    }}


All of the above is three ways to add the Word document background, if you like this article, welcome reprint (Reproduced please indicate the source)
PS: More about the Word,pdf,ppt,excel and other common Office documents operating skills, welcome to continue to pay attention to the blog, I hope to share more technical knowledge with you.

C # Action Word document--how to set the Word document background

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.