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
286 stars 50 forks source link

update(lists): add symbol font size option #196

Open tmpmachine opened 8 months ago

tmpmachine commented 8 months ago

Issue: Currently there's no way to set font size of the list's numbering/bullet symbol.

int listItemFontSize = 14;

WordList wordList1 = document.AddList(WordListStyle.Headings111, false);
wordList1.AddItem("Text 1", 0)
    .SetFontSize(listItemFontSize);
wordList1.AddItem("Text 2", 1);
wordList1.AddItem("Text 3", 2);

image

This PR adds the option to set the font size for numbering symbols in AddList().

// font size for both items and list's symbol
int listFontSize = 14;

WordList wordList1 = document.AddList(WordListStyle.Headings111, false, listFontSize);
wordList1.AddItem("Text 1", 0)
    .SetFontSize(listFontSize);
wordList1.AddItem("Text 2", 1);
wordList1.AddItem("Text 3", 2);

image

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

PrzemyslawKlys commented 8 months ago

Would you be able to add some tests around it? Checking that expectations meets reality?

tmpmachine commented 8 months ago

I'll take a look on the test code.

tmpmachine commented 8 months ago

Seems like the initial WordListStyle's NumberingSymbolRunProperties is being applied to the whole wordlist of the same style.

Not sure where to check next. Got any lead? Nevermind, I'm checking the markup now in open XML productivity tool.

image

// Heading1ai
{
    int listFontSize = 32;
    var wordList2 = doc.AddList(WordListStyle.Heading1ai, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}
{
    // font size on numbering symbol not applied
    int listFontSize = 10;
    var wordList2 = doc.AddList(WordListStyle.Heading1ai, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}

// Bulleted
{
    int listFontSize = 10;
    var wordList2 = doc.AddList(WordListStyle.Bulleted, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}
{
    // font size on numbering symbol not applied
    int listFontSize = 24;
    var wordList2 = doc.AddList(WordListStyle.Bulleted, false, listFontSize);
    foreach (var point in data.ListContent)
    {
        wordList2.AddItem($"{point}", 0)
            .SetFontSize(listFontSize);
    }
}
PrzemyslawKlys commented 8 months ago

After merging with master

image

internal static void Example_BasicLists8(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with lists - Document 8");
    string filePath = System.IO.Path.Combine(folderPath, "Document with Lists11.docx");
    using (WordDocument document = WordDocument.Create(filePath)) {

        // add list and nest a list
        WordList wordList1 = document.AddList(WordListStyle.Headings111, false, 15);
        wordList1.AddItem("Text 1");
        wordList1.AddItem("Text 1.1");
        wordList1.AddItem("Text 1.2");
        wordList1.AddItem("Text 1.3");

        document.AddParagraph("Second List");
        document.AddParagraph();

        WordList wordList2 = document.AddList(WordListStyle.Headings111, false, 25);
        wordList2.AddItem("Text 2");
        wordList2.AddItem("Text 2.1");
        wordList2.AddItem("Text 2.2");
        wordList2.AddItem("Text 2.3");
        wordList2.AddItem("Text 2.4");

        document.AddParagraph("Third List");
        document.AddParagraph();

        WordList wordList3 = document.AddList(WordListStyle.Headings111, false, 50);
        wordList3.AddItem("Text 3");
        wordList3.AddItem("Text 3.1");
        wordList3.AddItem("Text 3.2");
        wordList3.AddItem("Text 3.3");
        wordList3.AddItem("Text 3.4");

        document.Save(openWord);
    }
}

You're now ready to continue ;)

PrzemyslawKlys commented 8 months ago

Althought it still would be valid what's the difference between using it how you are using and how Word uses Paragraph Properties for that.

tmpmachine commented 8 months ago

awesome, thanks!