'How to set numbering format in lists docx4j

I’m trying to create numbered/bulleted lists but I want to be able to set which number format to use, example LOWER_LETTER, UPPER_LETTER, UPPER_ROMAN, etc. I referred to this: http://useof.org/java-open-source/org.docx4j.wml.NumFmt to create a numbering object but I’m not sure how to insert this in the word doc - the doc keeps erroring out when I do something like:
paragraph1.getContent().add(numbering); or wordMLPackage.getMainDocumentPart().addObject(numbering); .
Is there a better way to set which numbering format to use, or is there a way to get the NumberFormat object into the word doc? Thanks



Solution 1:[1]

In your numbering part, you need to create a w:num; see http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/num.html

Such a Numbering Definition Instance must reference an http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/abstractNum.html (either one which is there already), or a new one. Think of these as counters which increment each time a w:num in the docx uses them. That is, all w:num which use the same abstractNum increment the one counter.

To create these objects in your numbering definitions part, its easiest to use Word to get what you want, then upload a sample docx to http://webapp.docx4java.org/OnlineDemo/PartsList.html which can generate the code for you. Or use https://www.docx4java.org/forums/announces/docx4j-helper-addin-new-installer-available-t2946.html

Make sure the IDs are unique in your part.

Finally, to actually use your numbering scheme in your docx, you'll need to set w:numPr on your paragraph:

    <w:p>
        <w:pPr>
            <w:numPr>
                <w:ilvl w:val="0"/>
                <w:numId w:val="1"/>
            </w:numPr>
        </w:pPr>

where the w:vals reference your list definition (by numId) and list level (ilvl).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JasonPlutext