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);
Thursday, 12 November 2015 01:31

How to remove footnote from word document in C#

Written by support iceblue

Footnotes are the notes in the text of the document paper by using consecutive superscript numbers. The actual information is listed at the bottom of the page. With the help of Spire.Doc, we can easily add the footnote to the word document in C# and VB.NET. This article will show you how to remove the footnote from word document in C#.

Firstly, please view the original word document with footnote.

How to remove footnote from word document in C#

Note: Before Start, please download the latest version of Spire.Doc and add Spire.Doc.dll in the bin folder as the reference of Visual Studio.

Here comes to the steps of how to remove the footnote from word document.

Step 1: Create a new word document and load a file with footnote.

Document document = new Document();
document.LoadFromFile("Sample.docx");

Step 2: Get the first section for the document.

Section section = document.Sections[0];

Step 3: Find the footnote object and remove it.

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)
        para.ChildObjects.RemoveAt(index);
}

Step 4: Save the document to file.

document.SaveToFile("result.docx", FileFormat.Docx);

Effective screenshot after remove the footnote from the word document:

How to remove footnote from word document in C#

Full codes:

static void Main(string[] args)
 {

     Document document = new Document();
     document.LoadFromFile("Sample.docx");
     Section section = document.Sections[0];

     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)
           para.ChildObjects.RemoveAt(index);
     }

     document.SaveToFile("result.docx", FileFormat.Docx);

}

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);
Tuesday, 04 December 2012 06:40

Insert Endnote in Word in C#, VB.NET

Written by support iceblue

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.

Thursday, 14 June 2012 02:30

How to Add Footnote in Word with C#, VB.NET

Written by support iceblue

Footnote is one kind of annotations to explain one word or sentence in contents. It is often put on the bottom of one page. Because of footnote, users can learn some complicated words more clearly and the completeness can be preserved.

So, this guide will show how to add footnote in a Word document with C#/VB.NET by using Spire.Doc for .NET.

Friendly Reminder: Make Sure Spire.Doc and Visual Studio are correctly installed on system.

Step 1: Declare a new document and use document.LoadFromFile() to get Word document which you want to add footnote. Then, get the second paragraph for which the footnote will be given from the first section.

[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: Use paragraph.AppendFootnote() method to add footnote. The parameter passed to this method is FootnotType. Then, add footnote contents by using footnote.TextBody.AddParagraph().AppendText() method. Finally, set contents format, including font style, size and color.

[C#]
            Footnote footnote=paragraph.AppendFootnote(FootnoteType.Footnote);
            TextRange text = footnote.TextBody.AddParagraph().AppendText("Check Wiki to get more information");
            text.CharacterFormat.FontName = "Arial Black";
            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("Check Wiki to get more information")
            text.CharacterFormat.FontName = "Arial Black"
            text.CharacterFormat.FontSize = 12
            text.CharacterFormat.TextColor = Color.SlateGray

Step 3: As is known, there is a marker to be shown on the location where you want to add footnote. So this step is used to set marker format. Assign values for footnote.MarkerCharacterFormat.FontName/Fontsize/Bold/TextColor.

[C#]
            footnote.MarkerCharacterFormat.FontName = "Calibri";
            footnote.MarkerCharacterFormat.FontSize = 15;
            footnote.MarkerCharacterFormat.Bold = true;
            footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan;
[VB.NET]
            footnote.MarkerCharacterFormat.FontName = "Calibri"
            footnote.MarkerCharacterFormat.FontSize = 15
            footnote.MarkerCharacterFormat.Bold = True
            footnote.MarkerCharacterFormat.TextColor = Color.DarkCyan

Step 4: Save this document by using document.SaveToFile() method. There are two parameters passed: file name string and file format. Then, launch this file 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")

Insert Word Footnote

Insert Word Footnote

Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET. Click to learn more