EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
263 stars 47 forks source link

Add support for Footnotes and endnotes #154

Closed PrzemyslawKlys closed 1 year ago

PrzemyslawKlys commented 1 year ago

This PR aims to resolve:

internal static void Example_DocumentWithFootNotesEmpty(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with footnotes/end notes");
    string filePath = System.IO.Path.Combine(folderPath, "Document with FootNotes02.docx");
    using (WordDocument document = WordDocument.Create(filePath)) {
        var paragraph = document.AddParagraph("Basic paragraph");
        paragraph.ParagraphAlignment = JustificationValues.Center;

        document.AddParagraph("This is my text").AddFootNote("This is a footnote to my text")
            .AddText(" continuing").AddFootNote("2nd footnote!");

        Console.WriteLine("EndNotes count " + document.EndNotes.Count);
        Console.WriteLine("EndNotes Section count " + document.Sections[0].EndNotes.Count);

        Console.WriteLine("FootNotes count " + document.FootNotes.Count);
        Console.WriteLine("FootNotes Section count " + document.Sections[0].FootNotes.Count);

        var lastFootNoteParagraph = document.AddParagraph("Another paragraph").AddFootNote("more footnotes!")
            .AddText(" more within paragraph").AddFootNote("4th footnote!");

        Console.WriteLine("Is paragraph foot note: " + lastFootNoteParagraph.IsFootNote);

        var footNoteParagraphs = lastFootNoteParagraph.FootNote.Paragraphs;

        Console.WriteLine("Paragraphs within footnote: " + footNoteParagraphs.Count);
        Console.WriteLine("What's the text: " + footNoteParagraphs[1].Text);
        footNoteParagraphs[1].Bold = true;

        document.AddParagraph("Testing endnote - 1").AddEndNote("Test end note 1");

        document.AddParagraph("Test 1");

        document.AddSection();

        document.AddParagraph("Testing endnote - 2").AddEndNote("Test end note 2");

        Console.WriteLine("EndNotes count " + document.EndNotes.Count);
        Console.WriteLine("EndNotes Section count " + document.Sections[0].EndNotes.Count);

        Console.WriteLine("FootNotes count " + document.FootNotes.Count);
        Console.WriteLine("FootNotes Section count " + document.Sections[0].FootNotes.Count);

        document.Save(openWord);
    }
}