I am using $phpWord->getSettings()->setUpdateFields(true);
to create a table of contents.
In some versions of Word or a setting in word? it will ask the question to "Update Table of Contents".
If you choose "Update page numbers only" you get the formatting you expect in the TOC, but it is missing the first item/title. If you choose "Update entire table" it changes the formatting of the defined TOC and includes the missing first line. eg It changed it to 10
point from 12
.
The code you show - $phpWord->getSettings()->setUpdateFields(true);
- does not generate a table of contents. It sets a "marker" in the Word document that tells the Word application to update all fields in the document when the document is opened.
When Word updates the fields on opening a document where this setting is present, it will 1) prompt the user whether updating fields is allowed (security issue) and 2) the field updating will happen the same way as if the user requested the fields to update. In the case of a table of contents, this prompt is displayed. There's no option to suppress it.
This is different than updating fields from within the Word application using the COM object model. That has a specific command for updating a table of contents, and that suppresses the messages to the user.