XDoc.Word
Features
Tech Specs
How-to C#
Pricing

C# Word Library
C# Word - Section Processing in C#.NET


Provide a Series of Methods to Setup and Modify Sections in Word Document for Users





C#.NET Word document sections processing Interface control (XDoc.Word). It can help users to process sections on an existing or a new Word document by using our API.


Create Section in Word Document



The following demo code shows you how to create a new section for the document.

String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a section for document
ISection section = doc.CreateSection(0);
//Save the document
doc.Save(@"");


Pages Setup In Section



In C# class programming, you can use specific APIs in class IDocument to set Word pages. We can also set pages in each section, and the following demo code shows you how to do this work.

String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Create a section
ISection section = doc0.CreateSection(0);
//Section setup
//Create pageborders
section.CreatePageBorders();
//Page width
section.SetPageWidth(15000);
//Page height
section.SetPageHeight(12000);
//Margin
section.SetLeftMargin(500);
//Page orientation
section.SetPageLayout(OrientationType.Landscape);
//MORE TODO:
//
//Save the document
doc0.Save(@"");


Header and Footer Processing In Section



You can create header and footer in section with specified type. Before creating header or footer, you may need to check whether current section has included the same type of header or footer. If yes, it will not create new header or footer. What's more, you can also modify the header or footer existed in current section according to the standard supported by section. The following demo code shows how to create a header and footer in section.

String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main ducument
IDocument doc = document.GetDocument();
//Document clone
IDocument doc0 = doc.Clone();
//Get all setion
List<ISection> sections = doc0.GetAllSetion();
//Get the first section
ISection section = sections[0];
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//Create paragraph for header
IParagraph paraheader = header.CreateParagraph();
//Create run and text in para
IRun runheader = paraheader.CreateARun();
runheader.CreateText("Header Created in Section!");

//Create a footer for section
IFooter footer = section.CreateFooter(HeaderAndFooterType.Default);
//Create paragraph for footer
IParagraph parafooter = footer.CreateParagraph();
//Create run and text in para
IRun runfooter = parafooter.CreateARun();
runfooter.CreateText("Footer Created in Section!");

//Save the document
doc0.Save(@"");


Paragraph and Table Processing In Section



We provide methods for users to processing paragraph and table in section. You can use them to modify, delete, add and create paragraphs or tables in a section. The following demo code shows you how to create a table and paragraph in a section.

String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a empty paragraph for document
IParagraph paragraph = doc.CreateParagraph();
//Save the document
doc.Save(@"");