Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the background of Word document in C #

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to set up the background of Word documents in C#. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Word is an indispensable document processing tool in our daily life, study and work. Exquisite and beautiful documents can bring visual beauty when reading. In this article, I will show you how to use the component Free Spire.Doc for .NET (Community Edition) to set the document background for Word. In the following example, adding a background to Word is divided into three situations, namely, adding a solid background, a graded background, and a picture background.

Tool use: after downloading the installation control Free Spire.Doc, you can add Spire.Doc.dll to the project program (the dll can be obtained in the Bin folder under the installation file)

Add a solid color background

C#

Using Spire.Doc;using System.Drawing;namespace AddBackground {class Program {static void Main (string [] args) {/ / create a Document class object and load the Word document Document document = new Document (); document.LoadFromFile (@ "C:\ Users\ Administrator\ Desktop\ Test.docx") / / set the background fill mode of the document to document.Background.Type = Spire.Doc.Documents.BackgroundType.Color; / / set the background color document.Background.Color = Color.MistyRose; / / Save and open the document document.SaveToFile ("PureBackground.docx", FileFormat.Docx2013) System.Diagnostics.Process.Start ("PureBackground.docx");}

After debugging and running the program, generate documentation

Second, add a 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 the Word document Document document = new Document (); document.LoadFromFile (@ "C:\ Users\ Administrator\ Desktop\ Test.docx") / / set the background fill mode of the document to gradient fill document.Background.Type = Spire.Doc.Documents.BackgroundType.Gradient; / / set the gradient background color BackgroundGradient gradient = document.Background.Gradient; gradient.Color1 = Color.LightSkyBlue; gradient.Color2 = Color.PaleGreen / / set gradient mode gradient.ShadingVariant = GradientShadingVariant.ShadingMiddle; gradient.ShadingStyle = GradientShadingStyle.FromCenter; / / Save and open the document 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) {/ / create a Document class object and load the Word document Document document = new Document (); document.LoadFromFile (@ "C:\ Users\ Administrator\ Desktop\ Test.docx") / / set the background fill mode of the document to document.Background.Type = Spire.Doc.Documents.BackgroundType.Picture; / / set the background image document.Background.Picture = Image.FromFile (@ "C:\ Users\ Administrator\ Desktop\ 1.jpg"); / / Save and open the document document.SaveToFile ("ImageBackground.docx", FileFormat.Docx2013) System.Diagnostics.Process.Start ("ImageBackground.docx");}

This is the end of this article on "how to set the background of Word documents in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report