C# Word Library
C# Word - Header & Footer Processing in C#.NET
Provide a Series of Methods to Process Footer & Header in Word Document for C# Users
By using C#.NET Word document header & footer processing Interface control (XDoc.Word).//More TODO, users are able to process header and footer on Word document.
Create Footer & Header
The following C# sample code will show you how to create a header and footer in section. There's no content in section until blocks are created in it.
String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a section
ISection section = doc.CreateSection(0);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//More TODO:may create some block in header.
//Create a footer for section
IFooter footer = section.CreateFooter(HeaderAndFooterType.Default);
//More TODO:may create some block in footer.
//Save the document
doc.Save(@"");
Create and Add Paragraph to Footer & Header
Like main body story, header and footer of Word also contains a series of blocks such as normal paragraphs and tables. And we provide various methods to process them, the following demo code will show you how to create paragraph in header and footer.
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);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//Just Show how to Create a paragraph for header
IParagraph paragraph = header.CreateParagraph();
//Create a run and text in paragraph
IRun run = paragraph.CreateARun();
run.CreateText("Header");
//MORE TODO:
//
//
doc.Save(@"");
Create and Add Table to Footer & Header
The following demo code shows how to create table in footer and header.
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);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//Just show how to Create a table for header
ITable table= header.CreateTable(3, 3);
//MORE TODO:
//
//
doc.Save(@"");