News Category

Footnote

Footnote (5)

We have already demonstrated how to insert footnote to the word document with the help of Spire.Doc. This article we will show you how to set the position and number format for the footnote. The footnote position can be at the bottom of each page or below text. The default number format for the footnote is “1, 2, 3”. The following example shows how to set the position, number format, and the restart rule of footnote by calling the property of Section.FootnoteOptions.

Firstly, view the Footnote options under Microsoft Word and the original sample document file:

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

Step 1: Create a new instance of Document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2013);

Step 2: Get the first section from the document.

Section sec = doc.Sections[0];

Step 3: Set the number format, restart rule and position for the footnote.

sec.FootnoteOptions.NumberFormat = FootnoteNumberFormat.UpperCaseLetter;
sec.FootnoteOptions.RestartRule = FootnoteRestartRule.RestartPage;
sec.FootnoteOptions.Position = FootnotePosition.PrintAtBottomOfPage;

Step 4: Save the document to file.

doc.SaveToFile("Footnoteoptions.docx", FileFormat.Docx2013);

Effective screenshot after setting the formatting for the footnote.

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

Full codes of how to set the footnote options:

Document doc = new Document();
doc.LoadFromFile("Sample.docx", FileFormat.Docx2013);

Section sec = doc.Sections[0];

sec.FootnoteOptions.NumberFormat = FootnoteNumberFormat.UpperCaseLetter;
sec.FootnoteOptions.RestartRule = FootnoteRestartRule.RestartPage;
sec.FootnoteOptions.Position = FootnotePosition.PrintAtBottomOfPage;

////Clear all the formatting for the footnote and back to the default opitions
//sec.FootnoteOptions.ClearFormatting();

doc.SaveToFile("Footnoteoptions.docx", FileFormat.Docx2013);

Footnotes are notes placed at the bottom of a page. In MS Word, you can use footnotes to cite references, give explanations, or make comments without affecting the main text. In this article, you will learn how to insert or delete footnotes in a Word document using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Insert a Footnote after a Specific Paragraph in Word in C# and VB.NET

The Paragraph.AppendFootnote(FootnoteType.Footnote) method provided by Spire.Doc for .NET allows you to insert a footnote after a specified paragraph. The following are the detailed steps.

  • Create a Document instance
  • Load a sample Word document using Document.LoadFromFile() method.
  • Get the first section and then get a specified paragraph in the section.
  • Add a footnote at the end of the paragraph using Paragraph.AppendFootnote(FootnoteType.Footnote) method.
  • Set the text content, font and color of the footnote, and then set the format of the footnote superscript number.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace AddFootnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document document = new Document();

            //Load a sample Word document
            document.LoadFromFile("Sample.docx");

            //Get the first section
            Section section = document.Sections[0];

            //Get a specified paragraph in the section
            Paragraph paragraph = section.Paragraphs[3];

            //Add a footnote at the end of the paragraph
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);

            //Set the text content of the footnote
            TextRange text = footnote.TextBody.AddParagraph().AppendText("Algorithms can be simple or complex depending on what you want to achieve.");
            
            //Set the text font and color
            text.CharacterFormat.FontName = "Arial";
            text.CharacterFormat.FontSize = 12;
            text.CharacterFormat.TextColor = Color.DarkBlue;

            //Set the format of the footnote superscript number
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 15;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;

            //Save the result document
            document.SaveToFile("AddFootnote.docx", FileFormat.Docx);

        }
    }
}

C#/VB.NET: Insert or Remove Footnotes in Word

Insert a Footnote after a Specific Text in Word in C# and VB.NET

With Spire.Doc for .NET, a footnote can also be inserted after a specified text located anywhere in the document. The following are the detailed steps.

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Find a specified text using Document.FindString() method.
  • Get the text range of the specified text using TextSelection.GetAsOneRange() method.
  • Get the paragraph where the text range is located using TextRange.OwnerParagraph property.
  • Get the position index of the text range in the paragraph using Paragraph.ChildObjects.IndexOf() method.
  • Add a footnote using Paragraph.AppendFootnote(FootnoteType.Footnote) method, and then insert the footnote after the specified text using Paragraph.ChildObjects.Insert() method
  • Set the text content, font and color of the footnote, and then set the format of the footnote superscript number.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertFootnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document document = new Document();

            //Load a sample Word document
            document.LoadFromFile("Sample.docx");

            //Find a specified text string
            TextSelection selection = document.FindString("big O notation", false, true);

            //Get the text range of the specified text
            TextRange textRange = selection.GetAsOneRange();

            //Get the paragraph where the text range is located
            Paragraph paragraph = textRange.OwnerParagraph;

            //Get the position index of the text range in the paragraph
            int index = paragraph.ChildObjects.IndexOf(textRange);

            //Add a footnote
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);

            //Insert the footnote after the specified paragraph
            paragraph.ChildObjects.Insert(index + 1, footnote);

            //Set the text content of the footnote
            TextRange text = footnote.TextBody.AddParagraph().AppendText("It gives the worst-case complexity of an algorithm.");

            //Set the text font and color
            text.CharacterFormat.FontName = "Arial";
            text.CharacterFormat.FontSize = 12;
            text.CharacterFormat.TextColor = Color.DarkBlue;

            //Set the format of the footnote superscript number
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 15;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //Save the result document
            document.SaveToFile("InsertFootnote.docx", FileFormat.Docx);
        }
    }
}

C#/VB.NET: Insert or Remove Footnotes in Word

Remove Footnotes in a Word Document in C# and VB.NET

It takes time and effort to search and delete the existing footnotes in your document manually. The following are the steps to remove all footnotes at once programmatically.

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specified section using Document.Sections property.
  • Traverse through each paragraph in the section to find the footnote.
  • Remove the footnote using Paragraph.ChildObjects.RemoveAt() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace RemoveFootnote
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document document = new Document();

            //Load a sample Word document
            document.LoadFromFile("AddFootnote.docx");

            //Get the first section
            Section section = document.Sections[0];

            //Traverse through each paragraph in the section to find the footnote
            foreach (Paragraph para in section.Paragraphs)
            {
                int index = -1;
                for (int i = 0, cnt = para.ChildObjects.Count; i < cnt; i++)
                {
                    ParagraphBase pBase = para.ChildObjects[i] as ParagraphBase;
                    if (pBase is Footnote)
                    {
                        index = i;
                        break;
                    }
                }

                if (index > -1)

                    //Remove the footnote
                    para.ChildObjects.RemoveAt(index);
            }

            //Save the result document
            document.SaveToFile("RemoveFootnote.docx", FileFormat.Docx);
        }
    }
}

C#/VB.NET: Insert or Remove Footnotes in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

This article shows how to place a footnote in a paragraph using Spire.Doc for .NET, for example, after the word "Spire.Doc" in the following example:

Insert a footnote in a paragraph

Insert a footnote in a paragraph

Step 1: Load a word document, Sample.docx.

Document document1 = new Document();
document1.LoadFromFile("D:\\Sample.docx",FileFormat.Docx2010);

Step 2: Get the first paragraph of the first section of Sample.docx.

Paragraph paragraph1 = document1.Sections[0].Paragraphs[0];

Step 3: Add a footnote for paragraph1.

Footnote footnote1 = paragraph1.AppendFootnote(FootnoteType.Footnote);

Step 4: Find the word "Spire.Doc" and insert footnote1 after it.

DocumentObject obj=null;
for (int i = 0; i < paragraph1.ChildObjects.Count; i++)
{
   obj=paragraph1.ChildObjects[i];
   if (obj.DocumentObjectType == DocumentObjectType.TextRange)
   {
      TextRange textRange = obj as TextRange;
// Find the word "Spire.Doc" in paragraph1
if (textRange.Text == "Spire.Doc")
{
//Set bold format for the word "Spire.Doc"
textRange.CharacterFormat.Bold = true;
//Insert footnote1 after the word "Spire.Doc"
paragraph1.ChildObjects.Insert(i + 1, footnote1);
break;
}
     }
 }

Step 5: Type the footnote1 text and set the text's FontName, FontSize and Color.

TextRange text = footnote1.TextBody.AddParagraph().AppendText("Welcome to evaluate Spire.Doc");
text.CharacterFormat.FontName = "Arial Black";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.TextColor = Color.DarkGray;

Step 6: Set FontName, FontSize, Bold and Color for the footnote1 number.

footnote1.MarkerCharacterFormat.FontName = "Calibri";
footnote1.MarkerCharacterFormat.FontSize = 12;
footnote1.MarkerCharacterFormat.Bold = true;
footnote1.MarkerCharacterFormat.TextColor = Color.DarkGreen;

Step 7: Save Sample.docx to a new document, Footnote.docx.

document1.SaveToFile("D:\\ Footnote.docx"", FileFormat.Docx2010);

Full code:

Document document1 = new Document();
document1.LoadFromFile("D:\\Sample.docx" ,FileFormat.Docx2010);
Paragraph paragraph 1= document1.Sections[0].Paragraphs[0];
Footnote footnote1 = paragraph.AppendFootnote(FootnoteType.Footnote);
DocumentObject obj=null;
for (int i = 0; i < paragraph1.ChildObjects.Count; i++)
{
obj=paragraph1.ChildObjects[i];
if (obj.DocumentObjectType == DocumentObjectType.TextRange)
{
TextRange textRange = obj as TextRange;
// Find the word "Spire.Doc" in paragraph1
if (textRange.Text == "Spire.Doc")
{
//Set bold format for the word "Spire.Doc"
textRange.CharacterFormat.Bold = true;
//Insert footnote1 after the word "Spire.Doc"
paragraph1.ChildObjects.Insert(i + 1, footnote1);
break;
}
}
}
TextRange text = footnote1.TextBody.AddParagraph().AppendText("Welcome to evaluate Spire.Doc");
text.CharacterFormat.FontName = "Arial Black";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.TextColor = Color.DarkGray;

footnote1.MarkerCharacterFormat.FontName = "Calibri";
footnote1.MarkerCharacterFormat.FontSize = 12;
footnote1.MarkerCharacterFormat.Bold = true;
footnote1.MarkerCharacterFormat.TextColor = Color.DarkGreen;
document1.SaveToFile("Footnote.docx",FileFormat.Docx2010);

Word endnote is often put in the end of the document, which presents references of referred words/sentences/paragraphs. It includes two parts, marker and text. Marker can be customized or ordered automatically (i, ii, iii…). When one endnote is added, deleted or moved, the marker will be reordered automatically.

Spire.Doc for .NET, a stand-alone component used to manipulate Word document for .NET applications, enables users to insert endnote in Word by using C#, VB.NET. This guide introduces a method about how to realize this function via Spire.Doc for .NET.

Because endnote is included in footnote class, so invoke p.AppendFootnote(FootnoteType.Endnote) method to insert endnote. Then, use endnote.TextBody.AddParagraph().AppendText(string) method to add text and set CharacterFormat and MarkerCharacterFormat properties for endnote text and marker format. Download and install Spire.Doc for .NET and use the following code to insert endnote in Word.

Insert Word Endnote

[C#]
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace WordEndnote
{
    class InsertEndnote
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\Work\Documents\WordDocuments\Antarctic.docx", FileFormat.Docx);
            Section s = doc.Sections[0];
            Paragraph p = s.Paragraphs[3];

            //Add Footnote
            Footnote endnote = p.AppendFootnote(FootnoteType.Endnote);

            //Append Text
            TextRange text = endnote.TextBody.AddParagraph().AppendText("Reference: Wikipedia");

            //Text Format
            text.CharacterFormat.FontName = "Impact";
            text.CharacterFormat.FontSize = 14;
            text.CharacterFormat.TextColor = Color.DarkOrange;

            //Marker Format
            endnote.MarkerCharacterFormat.FontName = "Calibri";
            endnote.MarkerCharacterFormat.FontSize = 14;
            endnote.MarkerCharacterFormat.TextColor = Color.DarkBlue;

            //Save and Launch
            doc.SaveToFile("Endnote.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("Endnote.docx");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace WordEndnote
    Friend Class InsertEndnote
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim doc As New Document()
            doc.LoadFromFile("E:\Work\Documents\WordDocuments\Antarctic.docx", FileFormat.Docx)
            Dim s As Section = doc.Sections(0)
            Dim p As Paragraph = s.Paragraphs(3)

            'Add Footnote
            Dim endnote As Footnote = p.AppendFootnote(FootnoteType.Endnote)

            'Append Text
            Dim text As TextRange = endnote.TextBody.AddParagraph().AppendText("Reference: Wikipedia")

            'Text Format
            text.CharacterFormat.FontName = "Impact"
            text.CharacterFormat.FontSize = 14
            text.CharacterFormat.TextColor = Color.DarkOrange

            'Marker Format
            endnote.MarkerCharacterFormat.FontName = "Calibri"
            endnote.MarkerCharacterFormat.FontSize = 14
            endnote.MarkerCharacterFormat.TextColor = Color.DarkBlue

            'Save and Launch
            doc.SaveToFile("Endnote.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("Endnote.docx")
        End Sub
    End Class
End Namespace

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.

Footnotes and endnotes are short notes that can be used to provide explanations, comments or references to certain words or sentences in a document. Footnotes usually appear at the bottom of the page containing their reference numbers, while endnotes appear at the end of the document or section. If you are writing an academic paper in Word, inserting footnotes or endnotes may be essential. This article will demonstrate how to insert footnotes and endnotes in Word documents in C# and VB.NET using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Insert a Footnote in Word in C# and VB.NET

A footnote consists of two parts - a footnote reference mark and the corresponding footnote text. To insert a footnote for a specific text, you need to search for the text and get the paragraph where the text is located, after that add a footnote to the paragraph, then insert the footnote reference mark after the found text and set the footnote text. The detailed steps are as follows:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Search for a specific text in the document using Document.FindString() method and get the found text as a single text range using TextSelection.GetAsOneRange() method.
  • Access the owner paragraph of the text range through TextRange.OwnerParagraph property and get the index of the text range in the paragraph using Paragraph.ChildObjects.IndexOf() method.
  • Add a footnote to the paragraph using Paragraph.AppendFootnote(FootnoteType.Footnote) method.
  • Insert the footnote reference mark after the text range using Paragraph.ChildObjects.Insert() method.
  • Set the footnote text using Footnote.TextBody.AddParagraph().AppendText() method.
  • Set formatting such as font name, font size and text color for the footnote text and reference mark.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertFootnote
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document document = new Document();
            //Load a Word document
            document.LoadFromFile(@"Sample.docx");

            //Find a specific text in the document
            TextSelection selection = document.FindString("Spire.Doc for .NET", false, true);
            //Get the found text as a single text range
            TextRange textRange = selection.GetAsOneRange();
            //Get the owner paragraph of the text range
            Paragraph paragraph = textRange.OwnerParagraph;
            //Get the index of the text range in the paragraph
            int index = paragraph.ChildObjects.IndexOf(textRange);

            //Add a footnote to the paragraph
            Footnote footnote = paragraph.AppendFootnote(FootnoteType.Footnote);
            //Insert the footnote reference mark after the text range
            paragraph.ChildObjects.Insert(index + 1, footnote);
            //Set the footnote text
            textRange = footnote.TextBody.AddParagraph().AppendText("Developed by E-iceblue Co., LTD.");

            //Set format for the footnote text
            textRange.CharacterFormat.FontName = "Arial Black";
            textRange.CharacterFormat.FontSize = 12;
            textRange.CharacterFormat.TextColor = Color.DarkGray;

            //Set format for the footnote reference mark
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 12;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //Save the result document
            document.SaveToFile("InsertFootnote.docx", FileFormat.Docx2013);
            document.Close();
        }
    }
}

C#/VB.NET: Insert Footnotes and Endnotes in Word Documents

Insert an Endnote in Word in C# and VB.NET

An endnote also consists of two parts - an endnote reference mark and the corresponding endnote text. The steps to insert an endnote for a specific text are very similar to that of the above example:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Search for a specific text in the document using Document.FindString() method and get the found text as a single text range using TextSelection.GetAsOneRange() method.
  • Access the owner paragraph of the text range through TextRange.OwnerParagraph property and get the index of the text range in the paragraph using Paragraph.ChildObjects.IndexOf() method.
  • Add an endnote to the paragraph using Paragraph.AppendFootnote(FootnoteType.Endnote) method.
  • Insert the endnote reference mark after the text range using Paragraph.ChildObjects.Insert() method.
  • Set the endnote text using Footnote.TextBody.AddParagraph().AppendText() method.
  • Set formatting such as font name, font size and text color for the endnote text and reference mark.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace InsertEndnote
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document document = new Document();
            //Load a Word document
            document.LoadFromFile(@"Sample.docx");

            //Find a specific text in the document
            TextSelection selection = document.FindString("Microsoft Office", false, true);
            //Get the found text as a single text range
            TextRange textRange = selection.GetAsOneRange();
            //Get the owner paragraph of the text range
            Paragraph paragraph = textRange.OwnerParagraph;
            //Get the index of the text range in the paragraph
            int index = paragraph.ChildObjects.IndexOf(textRange);

            //Add an endnote to the paragraph
            Footnote endnote = paragraph.AppendFootnote(FootnoteType.Endnote);
            //Insert the endnote reference mark after the text range
            paragraph.ChildObjects.Insert(index + 1, endnote);
            //Set the endnote text
            textRange = endnote.TextBody.AddParagraph().AppendText("Developed by Microsoft.");

            //Set format for the endnote text
            textRange.CharacterFormat.FontName = "Arial Black";
            textRange.CharacterFormat.FontSize = 12;
            textRange.CharacterFormat.TextColor = Color.DarkGray;

            //Set format for the endnote reference mark
            endnote.MarkerCharacterFormat.FontName = "Calibri";
            endnote.MarkerCharacterFormat.FontSize = 12;
            endnote.MarkerCharacterFormat.Bold = true;
            endnote.MarkerCharacterFormat.TextColor = Color.DarkGreen;

            //Save the result document
            document.SaveToFile("InsertEndnote.docx", FileFormat.Docx2013);
            document.Close();
        }
    }
}

C#/VB.NET: Insert Footnotes and Endnotes in Word Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.