-2

I want to create a word document using Java and want to add a bullet list to the document. The bullet has to be round shaped or check mark and not numbers. I was able to create a bullet list of numbers using XWPF but not the round shaped or check mark bullets. Please share some examples showing how to create the round/checkmark type bullets in word using Java.

javac
  • 2,431
  • 4
  • 17
  • 26

1 Answers1

1

It would be so hard to explain, but here's a function:

public static BigInteger addListStyle(XWPFDocument doc, char symbol) throws XmlException{

        String styleMaybe = "<w:numbering xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\">\n" + 
                                        "<w:abstractNum w:abstractNumId=\""+listStyleIDCounter+"\">\n" + 
                                                "<w:nsid w:val=\"6871722E\"/>\n" + 
                                                "<w:multiLevelType w:val=\"hybridMultilevel\"/>\n" + 
                                                "<w:tmpl w:val=\"8FE6E4C8\"/>\n" + 
                                                "<w:lvl w:ilvl=\"0\" w:tplc=\"0410000D\">\n" + 
                                                        "<w:start w:val=\"1\"/>\n" + 
                                                        "<w:numFmt w:val=\"bullet\"/>\n" + 
                                                        "<w:lvlText w:val=\""+symbol+"\"/>\n" + 
                                                        "<w:lvlJc w:val=\"left\"/>\n" + 
                                                        "<w:pPr>\n" + 
                                                                "<w:ind w:left=\"720\" w:hanging=\"360\"/>\n" + 
                                                        "</w:pPr>\n" + 
                                                                "<w:rPr>\n" + 
                                                                "<w:rFonts w:ascii=\"Webdings\" w:hAnsi=\"Webdings\" w:hint=\"default\"/>\n" + 
                                                        "</w:rPr>\n" + 
                                                "</w:lvl>\n" + 
                                        "</w:abstractNum>\n" + 
                                        "<w:num w:numId=\"1\">\n" + 
                                        "<w:abstractNumId w:val=\"0\"/>\n" + 
                                        "</w:num>\n" + 
                                "</w:numbering>";



    XWPFNumbering numbering = doc.createNumbering();

    // genero il numbering style dall'XML
    CTAbstractNum abstractNum = CTAbstractNum.Factory.parse(styleMaybe);
    XWPFAbstractNum abs = new XWPFAbstractNum(abstractNum, numbering);
    // gli imposto un ID univoco
    BigInteger id = BigInteger.valueOf(listStyleIDCounter++);

    // assegno l'id all'abs
    abs.getAbstractNum().setAbstractNumId(id);

    // ora aggiungo l'abs al CT del numbering, che mi dovrebbe ritornare lo stesso id
    id = numbering.addAbstractNum(abs);
    // ora lo aggiungo al numbering creato prima che mi restituirà ancora lo stesso id
    return doc.getNumbering().addNum(id);
}

where listStyleIDCounter is a static counter starting from 0.

you can pass a for check symbol, = for a small circle and < for small square, and other more symbols you can try by yourself :D