title: Apache POI Table of contents not updating
body: <p>I am using Apache POI XWPF components and java, to extract data from a .xml file into a word document. So far so good, but I am struggling to create a table of contents. I have to create a table of contents at the start of the method and then I update it at the end to get all the new headers. Currently I use doc.createTOC(), where doc is a variable created from XWPFDocument, to create the table at the start and then I use doc.enforceUpdateFields() to update everything at the end of the document. But when I open the document after I ran the program, the table of contents is empty, but the navigation panel does include some of the headers I specified.</p>
  
  <p>A comment recommended that I include some code. So i started off by create the document from a template:</p>
  
  <pre><code>XWPFDocument doc = new XWPFDocument(new FileInputStream("D://Template.docx"));
  </code></pre>
  
  <p>I then create a table of contents:</p>
  
  <pre><code>doc.createTOC();
  </code></pre>
  
  <p>Then throughout the method I add headers to the document:</p>
  
  <pre><code>XWPFParagraph documentControlHeading = doc.createParagraph();
  documentControlHeading.setPageBreak(true);
  documentControlHeading.setAlignment(ParagraphAlignment.LEFT);
  documentControlHeading.setStyle("Tier1Header");
  </code></pre>
  
  <p>After all the headers are added, I want to update the document so that all the new headers will appear in the table of contents. I do this buy using the following command:</p>
  
  <pre><code>doc.enforceUpdateFields();
  </code></pre>