Page 1 of 1

ToC update doesn't work #2

PostPosted: Mon Nov 21, 2016 10:09 pm
by sanju_c88
Hi Jason,

I too seem to have the same error!!

Exception in thread "main" org.docx4j.toc.TocException: No ToC content control found
at org.docx4j.toc.TocGenerator.updateToc(TocGenerator.java:494)
at org.docx4j.toc.TocGenerator.updateToc(TocGenerator.java:465)

I can find this control in the document I'm working with.
<w:instrText xml:space="preserve">TOC \o "1-3" \* MERGEFORMAT</w:instrText>

However, I did not understand the solution or approach you suggested for the same.
(Sorry I'm new to working with Docx4j and Word documents as such!!)

Could you please help me here!!

Thanks,
Sanjay

Re: ToC update doesn't work #2

PostPosted: Tue Nov 22, 2016 7:20 am
by jason
It is not enough to have the field <w:instrText xml:space="preserve">TOC \o "1-3" \* MERGEFORMAT</w:instrText>

It must be in a suitable content control (w:sdt), as inserted by Word (since 2007, i think). For example:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <w:sdt>
            <w:sdtPr>

                <w:docPartObj>
                    <w:docPartGallery w:val="Table of Contents"/>
                    <w:docPartUnique/>
                </w:docPartObj>
            </w:sdtPr>

            <w:sdtContent>
                <w:p w:rsidR="00AA1D1B" w:rsidP="00AA1D1B" w:rsidRDefault="00AA1D1B">
                    <w:pPr>
                        <w:pStyle w:val="TOCHeading"/>
                    </w:pPr>
                    <w:r>
                        <w:t>Contents</w:t>
                    </w:r>
                </w:p>
                <w:p w:rsidR="00AA1D1B" w:rsidP="00AA1D1B" w:rsidRDefault="00AA1D1B">
                    <w:pPr>
                        <w:pStyle w:val="TOC1"/>
                        <w:tabs>
                            <w:tab w:val="right" w:leader="dot" w:pos="9350"/>
                        </w:tabs>
                        <w:rPr>
                            <w:noProof/>
                        </w:rPr>
                    </w:pPr>
                    <w:r>
                        <w:fldChar w:fldCharType="begin"/>
                    </w:r>
                    <w:r>
                        <w:instrText xml:space="preserve"> TOC \o "1-3" \h \z \u </w:instrText>
                    </w:r>
etc
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Please check your docx contains that w:sdt. (Unzip the docx; look at /word/document.xml)