How to Add Footnote in Word by Using C#/VB.NET
Footnote which is always put at the end of one page and separated from contents, is additional information to explain some words or sentences in a Word document.
Generally speaking, if users want to explain one complicated word or show some additional description of one paragraph, they would like to add footnote because footnote will not influence integrity of original contents and help readers learn more information which is related to this document.
In this post, I want to introduce a method about how to add footnote in Word document by using C#/VB.NET. Also, Spire.Doc is used in this example for meeting my requirements more quickly and easily.
Steps
Step 1. Load Document
Use document.LoadFromFile() method to get document which I want to add footnote. Then, get the second paragraph in the first section. Note: title is paragraph 1.
C#
Document document = new Document();
document.LoadFromFile(@"E:\work\documents\Antarctic.docx");
Section section = document.Sections[0];
Paragraph paragraph = section.Paragraphs[1];
VB.NET
Dim document As New Document()
document.LoadFromFile("E:\work\documents\Antarctic.docx")
Dim section As Section = document.Sections(0)
Dim paragraph As Paragraph = section.Paragraphs(1)
Step 2. Add Footnote
Use paragraph.AppendFootnote() method to add footnote. The parameter is passed to this method is foot note type. Then, add footnote content by using footnote.TextBody.AddParagraph().AppendText() method. After that, set format for footnote content.
C#
Footnote footnote=paragraph.AppendFootnote(FootnoteType.Footnote);
TextRange text = footnote.TextBody.AddParagraph().AppendText("If you want to get more information of Antarctic, please check from wiki.");
text.CharacterFormat.FontName = "Arial Narrow";
text.CharacterFormat.FontSize = 12;
text.CharacterFormat.TextColor = Color.SlateGray;
VB.NET
Dim footnote As FootNote = paragraph.AppendFootnote(FootnoteType.Footnote)
Dim text As TextRange = footnote.TextBody.AddParagraph().AppendText("If you want to get more information of Antarctic, please check from wiki.")
text.CharacterFormat.FontName = "Arial Narrow"
text.CharacterFormat.FontSize = 12
text.CharacterFormat.TextColor = Color.SlateGray
Actually, footnote is formed with content and marker, which is often shown as number. In this step, I will set format for marker.
C#
footnote.MarkerCharacterFormat.FontName = "Century Gothic";
footnote.MarkerCharacterFormat.FontSize = 15;
footnote.MarkerCharacterFormat.Bold = true;
footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;
VB.NET
footnote.MarkerCharacterFormat.FontName = "Century Gothic"
footnote.MarkerCharacterFormat.FontSize = 15
footnote.MarkerCharacterFormat.Bold = True
footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan
Step 3. Save and Launch
Save this document by using document.SaveToFile() method and then launch it for viewing.
C#
document.SaveToFile("FootNote.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("FootNote.docx");
VB.NET
document.SaveToFile("FootNote.docx", FileFormat.Docx)
System.Diagnostics.Process.Start("FootNote.docx")
RESULT
_______________________________________________________________________________________________
Click Here to LEARN MORE about Spire.Doc
Click Here to DOWNLOAD Spire.Doc
Spire.Office also can be used to realize this function.