Hey,
so I managed to figure out how the styles and numbering parts work together.
First, I used the example code, to create a numbering part. I added references in the level elements to the styles I want to number ( Styles 1 through 7) It looks kind of like this:
- Code: Select all
<w:lvl w:ilvl=\"0\">"
+ "<w:pStyle w:val=\"Heading1\"/>"
+ "<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:left=\"360\" w:hanging=\"360\"/>"
+ "</w:pPr>"
+ "</w:lvl>"
This works fine and is present in the document. The second part however doesn't want to behave the way I want it to. here is what happens:
Like in previous post, I unmarshall the default styles (to not having the create the headings by myself). I add them to the document.
After this, I now added a initialization method to reference my numbering to the headings:
- Code: Select all
void initStyleNumbering() {
for (Style style : Style.values()) {
if (style == Style.DEFAULT) {
continue;
}
org.docx4j.wml.Style styleObj = style.getStyle();
PPr stylePpr = styleObj.getPPr();
NumPr numPr = objFactory.createPPrBaseNumPr();
NumId nId = new NumId();
nId.setVal(BigInteger.valueOf( 1 ));
numPr.setNumId(nId);
stylePpr.setNumPr(numPr);
}
}
This method adds the reference to heading styles.
When I further debug to the place I actually add a heading and check on the style object, the numbering is referenced.
After my whole document is created, I save it by calling the save method:
- Code: Select all
public void saveDocument() throws Docx4JException, JAXBException {
wordMLPackageFATScript.save(new File(path));
}
This works fine too.
However there is a problem with the document now. When I open it, there is no numbering. When I unzip it, and check the styles file, the styles I changed before, are unchanged again. non of my references are included anymore, so there is no way there can be numbering in the document. I know however, that I am heading down the right path, because:
After I saw that my references are gone, I manually typed them in (after unzipping my file) and saved the styles.xml. I zipped it again and opened it with MS Word 07 and there's my numbering in the styles.
So do you have any idea, why my Numbering references are gone after saving my document. is there any option I need to enable for this to be working?
On reference to the TOC before. You told me to set the TOC flag to dirty. I am not sure how to do this ...
Best regards and thanks for your help so far
,
-- artur