[]
The purpose of using footnotes and endnotes in a document is to explain or provide additional information in a document like a reference or credits to something or someone mentioned in a document. The difference between footnotes and endnotes is that a footnote is displayed at the bottom of each page of a document and endnote appears at the end of a section or a document.
GcWord allows you to add a footnote and endnote using Add method of the FootnoteCollection class and EndnoteCollection class respectively. It lets you set the footnote and endnote position, numbering rule and number style for a document or a section using the FootnoteOptions and EndnoteOptions class respectively. These classes can be accessed using FootnoteOptions and EndnoteOptions properties of the Settings class respectively.
To add a footnote and endnote:
Set the footnote and endnote options using the FootnoteOptions property and the EndnoteOptions property respectively.
Access a content object to which a footnote and endnote needs to be added. For example, access a section of the document.
Add a footnote using Add method of the FootnoteCollection class.
Add an endnote using Add method of the EndnoteCollection class.
doc.Load("HeaderFooter.docx");
//Set footnote options
doc.Settings.FootnoteOptions.Location = FootnoteLocation.BottomOfPage;
doc.Settings.FootnoteOptions.NumberingRule = FootnoteNumberingRule.Continuous;
//Add footnote in first section
var section = doc.Body.Sections.First;
section.GetRange().Paragraphs.First.GetRange().Footnotes.Add("This is a test footnote.");
//Add footnote in second section
var section2 = doc.Body.Sections[1];
var secondRun = section2.GetRange().Paragraphs.First.GetRange().Runs.Insert(InsertLocation.End);
secondRun.GetRange().Texts.Add("This is a reference text for a footnote.");
secondRun.GetRange().Footnotes.Add("Footnote for second section");
//Set endnote options
doc.Settings.EndnoteOptions.Location = EndnoteLocation.EndOfDocument;
doc.Settings.EndnoteOptions.NumberingRule = EndnoteNumberingRule.Continuous;
//Add endnote at the end of the document
section.GetRange().Paragraphs[1].GetRange().Endnotes.Add("This is a test endnote.");
//Save the document
doc.Save("AddNotes.docx");
To modify a footnote and endnote:
Modify the footnote and endnote option using the FootnoteOptions property and the EndnoteOptions property respectively. For example, modify the location.
Access the footnote and endnote which needs to be modified. For example, access the first footnote and endnote added to the document.
Modify text of the footnote and endnote added to the document using Value property of the Text class.
doc.Load("AddNotes.docx");
//Modify footnote options
doc.Settings.FootnoteOptions.Location = FootnoteLocation.EndOfSection;
//Modify the footnote in first section
var section = doc.Body.Sections.First;
section.GetRange().Paragraphs.First.GetRange().Footnotes.First.Body.Texts.First.Value = "This" +
" is a modified test footnote.";
//Modify endnote
doc.Settings.EndnoteOptions.Location = EndnoteLocation.EndOfSection;
//Modify the endnote in first section
section.GetRange().Paragraphs[1].GetRange().Endnotes.First.Body.Texts.First.Value = "This" +
" is a modified test endnote.";
//Save the document
doc.Save("ModifyNotes.docx");
To delete a footnote and endnote, access the footnote and endnote and delete them using Delete method of the ContentObject class.
doc.Load("AddNotes.docx");
//Add footnote in first section.
var section2 = doc.Body.Sections[1];
section2.GetRange().Paragraphs.First.GetRange().Footnotes.First.Delete();
//Delete EndNote
var section = doc.Body.Sections.First;
section.GetRange().Paragraphs[1].GetRange().Endnotes.First.Delete();
//Save the document
doc.Save("DeleteNotes.docx");
To set numbering style of footnotes and endnotes:
Access the footnote and endnote options using the FootnoteOptions and EndnoteOptions property respectively.
Set the numbering style for the footnotes and endnotes using NumberStyle property of the FootnoteOptions and EndnoteOptions class respectively, which takes value from the NumberStyle enumeration.
doc.Load("AddNotes.docx");
//Set footnote numbering style
doc.Settings.FootnoteOptions.NumberStyle = NumberStyle.DecimalEnclosedCircle;
//Set endnote numbering style
doc.Settings.EndnoteOptions.NumberStyle = NumberStyle.NumberInDash;
//Save the document
doc.Save("SetNumbering.docx");
For more information on how to implement footnotes and endnotes in a Word document using GcWord, see GcWord sample browser.