1. Apple
1. Orange
2. Pear
2. Banana
But when I do it with the bottom code the numbers 1 and 2 in the nested list infront of Orange and Pear disappear. Any clues?
- Code: Select all
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
String str =
"<w:numbering xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"+
"<w:abstractNum w:abstractNumId=\"0\">"+
"<w:nsid w:val=\"369E7F02\"/>"+
"<w:multiLevelType w:val=\"hybridMultilevel\"/>"+
"<w:tmpl w:val=\"89B427B2\"/>"+
"<w:lvl w:ilvl=\"0\" w:tplc=\"041D000F\">"+
"<w:start w:val=\"1\"/>"+
"<w:numFmt w:val=\"decimal\"/>"+
"<w:lvlText w:val=\"%1.\"/>"+
"<w:lvlJc w:val=\"left\"/>"+
"<w:pPr>"+
"<w:ind w:hanging=\""+300+"\" w:left=\""+300+"\"/>"+
"</w:pPr>"+
"</w:lvl>"+
"<w:lvl w:ilvl=\"1\" w:tplc=\"041D000F\">"+
"<w:start w:val=\"1\"/>"+
"<w:numFmt w:val=\"decimal\"/>"+
"<w:lvlText w:val=\"%1.\"/>"+
"<w:lvlJc w:val=\"left\"/>"+
"<w:pPr>"+
"<w:ind w:hanging=\""+600+"\" w:left=\""+600+"\"/>"+
"</w:pPr>"+
"</w:lvl>"+
"</w:abstractNum>"+
"<w:num w:numId=\"1\">"+
"<w:abstractNumId w:val=\"0\"/>"+
"</w:num>"+
"<w:num w:numId=\"2\">"+
"<w:abstractNumId w:val=\"0\"/>"+
"</w:num>"+
"</w:numbering>";
ndp.unmarshal(new ByteArrayInputStream(str.getBytes()));
mdp.addTargetPart(ndp);
long list1NumId = ndp.restart(1,0,1);
str =
"<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidP=\"00FF661E\" w:rsidRDefault=\"00FF661E\" w:rsidR=\"00000000\">"+
"<w:pPr>"+
"<w:pStyle w:val=\"ListParagraph\"/>"+
"<w:numPr>"+
"<w:ilvl w:val=\"0\"/>"+
"<w:numId w:val=\""+list1NumId+"\"/>"+
"</w:numPr>"+
"</w:pPr>"+
"<w:r>"+
"<w:t>test1</w:t>"+
"</w:r>"+
"</w:p>";
mdp.addObject(org.docx4j.XmlUtils.unmarshalString(str) );
long list2NumId = ndp.restart(2,1,1);
str =
"<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidP=\"00FF661E\" w:rsidRDefault=\"00FF661E\" w:rsidR=\"00000000\">"+
"<w:pPr>"+
"<w:pStyle w:val=\"ListParagraph\"/>"+
"<w:numPr>"+
"<w:ilvl w:val=\"1\"/>"+
"<w:numId w:val=\""+list2NumId+"\"/>"+
"</w:numPr>"+
"</w:pPr>"+
"<w:r>"+
"<w:t>test2</w:t>"+
"</w:r>"+
"</w:p>";
mdp.addObject(org.docx4j.XmlUtils.unmarshalString(str) );
str =
"<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidP=\"00FF661E\" w:rsidRDefault=\"00FF661E\" w:rsidR=\"00000000\">"+
"<w:pPr>"+
"<w:pStyle w:val=\"ListParagraph\"/>"+
"<w:numPr>"+
"<w:ilvl w:val=\"1\"/>"+
"<w:numId w:val=\""+list2NumId+"\"/>"+
"</w:numPr>"+
"</w:pPr>"+
"<w:r>"+
"<w:t>test3</w:t>"+
"</w:r>"+
"</w:p>";
mdp.addObject(org.docx4j.XmlUtils.unmarshalString(str) );
str =
"<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidP=\"00FF661E\" w:rsidRDefault=\"00FF661E\" w:rsidR=\"00000000\">"+
"<w:pPr>"+
"<w:pStyle w:val=\"ListParagraph\"/>"+
"<w:numPr>"+
"<w:ilvl w:val=\"0\"/>"+
"<w:numId w:val=\""+list1NumId+"\"/>"+
"</w:numPr>"+
"</w:pPr>"+
"<w:r>"+
"<w:t>test4</w:t>"+
"</w:r>"+
"</w:p>";
mdp.addObject(org.docx4j.XmlUtils.unmarshalString(str) );
wordMLPackage.save(new java.io.File("wordfile.docx") );
}