DOCX4J not updating TOC

31 views Asked by At

Bonjour,

I was able to generate a Word document with Docx4j (docx4j-JAXB-ReferenceImpl Version 11.4.10) from a template. I am trying to update the TOC of it which is defined in the template.

This produces no error but the TOC is not filled. But, this TOC is not that bad since I can update it manually by opening the produced document in Word.

I made a short Eclipse Spring project you'll find here.

Then, I tried to generate the TOC with Docx4j (in same project). Same result.

Best Regards,

Edile

1

There are 1 answers

1
JasonPlutext On

You have: tocGenerator.generateToc(1, " TOC \\h \\z \\t \"EnTete1;1;EnTete2;2;EnTete3;3\" ", STTabTlc.DOT, false);

However, the t switch field args are supposed to be separated by commas:

Uses paragraphs formatted with styles other than the built-in heading styles. text in this switch's field-argument specifies those styles as a set of comma-separated doublets, with each doublet being a comma-separated set of style name and table of content level. \t can be combined with \o.

See http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/TOC.html

so try instead:

tocGenerator.generateToc(1, " TOC \\h \\z \\t \"EnTete1,1,EnTete2,2,EnTete3,3\" ", STTabTlc.DOT, true);

Note: here I have also switched off page number generation since that requires additional config.