How to Use C# Insert Borders in Word Document
Borders are very common in Microsoft Excel worksheet. There we can design border style at will. However, in Microsoft Word, to beautify Word document content, borders can also be inserted with different styles. In This article,
you will be introduced a solution to insert border in Word document by using C#.
Borders in Word document can be used to decorate Word document if we can set border style and color. Spire.Doc for .NET, as a professional .NET Word document, it can help us easily insert borders in Word document with styles and color designed.
Download Spire.Doc for .NET Here. Make sure Spire.Doc for .NET and Visual Studio are correctly installed on system. Follow the simple steps below to insert borders in Word document with C#.
Step 1 Create Project
Create a C# project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
Step 2 Load Word Document
Load the word document which we need insert borders. Use the following code below to do the job:
Document document = new Document();
document.LoadFromFile(@”E:\work\Documents\Antarctic.docx”);
Section section = document.Sections[0];
Step 3 Insert Borders in Word Document
First, follow the code below to insert and set border style.
section.PageSetup.Borders.BorderType = BorderStyle.ThickThinLargeGap;
section.PageSetup.Borders.Color = Color.DeepSkyBlue;
Second, set alignment for the borders.
section.PageSetup.Borders.Left.Space = 100;
section.PageSetup.Borders.Right.Space = 100;
Step 4 Save and Preview
After setting styles, save the design by using the code below.
document.SaveToFile(“WordBorders.docx”, FileFormat.Docx);
System.Diagnostics.Process.Start(“WordBorders.docx”);
Effective Screenshot:
you will be introduced a solution to insert border in Word document by using C#.
Borders in Word document can be used to decorate Word document if we can set border style and color. Spire.Doc for .NET, as a professional .NET Word document, it can help us easily insert borders in Word document with styles and color designed.
Download Spire.Doc for .NET Here. Make sure Spire.Doc for .NET and Visual Studio are correctly installed on system. Follow the simple steps below to insert borders in Word document with C#.
Step 1 Create Project
Create a C# project in visual studio add Spire.Doc.dll as reference. The default setting of Spire.Doc.dll is placed under "C:\Program Files\e-iceblue\Spire.Doc\Bin”. Select assembly Spire.Doc.dll and click OK to add it to the project.
Step 2 Load Word Document
Load the word document which we need insert borders. Use the following code below to do the job:
Document document = new Document();
document.LoadFromFile(@”E:\work\Documents\Antarctic.docx”);
Section section = document.Sections[0];
Step 3 Insert Borders in Word Document
First, follow the code below to insert and set border style.
section.PageSetup.Borders.BorderType = BorderStyle.ThickThinLargeGap;
section.PageSetup.Borders.Color = Color.DeepSkyBlue;
Second, set alignment for the borders.
section.PageSetup.Borders.Left.Space = 100;
section.PageSetup.Borders.Right.Space = 100;
Step 4 Save and Preview
After setting styles, save the design by using the code below.
document.SaveToFile(“WordBorders.docx”, FileFormat.Docx);
System.Diagnostics.Process.Start(“WordBorders.docx”);
Effective Screenshot:
By using Spire.Doc for .NET, developers/programmers can esily insert borders in Word documents. Besides, Spire.Doc for .NET enables user to perform a wide range of Word document processing tasks directly, such as
generate, read, write and modify Word document for .NET. It supports C#, VB.NET, ASP.NET, ASP.NET and MVC. Click to learn more...
generate, read, write and modify Word document for .NET. It supports C#, VB.NET, ASP.NET, ASP.NET and MVC. Click to learn more...