C#: Online Guide
How To: Word SDK
Section Processing
Section Processing
  |  
Home ›› XDoc.Word ›› C# Word: Process Section

C# Word - Section Processing in C#.NET


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




Overview



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


Related .net document control helps:
c# asp.net powerpoint document viewer: ASP.NET PowerPoint Document Viewer Control: view pptx files online in C# using ASP.NET
c# asp.net dicom document viewer: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET
c# asp.net tiff document viewer: ASP.NET Tiff Document Viewer: view, annotate Tiff files in HTML using C# Control
asp.net dotnetnuke pdf editor using c#: ASP.NET DNN PDF Editor Control: view, edit PDF files in Dotnetnuke application
c# asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
c# asp.net dnn document viewer: DNN Document Viewer Control: view, annotate, redact, convert documents in dotnetnuke ASP.NET
asp.net doc document viewer: ASP.NET Office Word Document Viewer: view MS Office Word files online using C# in ASP.NET web applications




C# DLLs: Word Section Processing



Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Word;




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(@"");