Inserting TOC (Table of Contents) in Aspose.Word

We have been trying to implement the following functionality:

a) Insert data automatically into a word document that includes the index. Index should be automatically updated after the data has been inserted (as it obviously makes the document larger). This is NOT possible (compare email at the bottom). We obviously can’t expect the user the click on F9 after opening the word to refresh the TOC.

Consequence: TOC not usuable in Word??

In general you are correct about all points.

Aspose.Word does not calculate field values so when the TOC (and it is a field) is inserted, it will appear empty in the document until the field is recalculated and this can only be done in MS Word at the moment.

Recalculating fields in MS Word can be done using F9 or automation.

So please be careful when planning to programmatically insert fields into Word documents and using Aspose.Word as the results will not be automatically updated.

Possible known workarounds for the TOC issue (successfully used by some customers):

  1. After creating the document using Aspose.Word, fire up MS Word using automation and refresh the fields.
  2. Create a “pseudo” toc that consists of hyperlinks to local bookmarks in the document. Such a toc will not display page numbers, but will display hyperlinks. It will be okay for online documents, but of course not really suitable for printed material.