TOC field - UpdateFields does not udate if table of contents is inside a table

I am having an issue with the TOC field and UpdateFields in version 10.6. I use builder.InsertTableOfContents(), generate a document with some headings, and call updatefields. If the able of contents is not located inside a table, everything works correctly. If it is inside a table, the page numbers do not get output. The links do point to the correct location - but the page numbers are not displayed.
In the example code below, I have a template doc with a mergefield named “toc”. If the “toc” mergefield is not in a table, everything works correctly. If the “toc” mergefield is in a table, the toc page numbers are not output. Also if there is a table before the toc, it does not get updated properly.
I also tried adding a call to doc.UpdateTableLayout but that does not change anything.

// Open the template document.
AW.Document doc = new AW.Document(tocFilename);
// Create a document builder to insert content with into document.
AW.DocumentBuilder builder = new AW.DocumentBuilder(doc);
string tocswitches = "\\o \"1-4\" \\h \\z \\u";
AW.Fields.Field tocfield = builder.InsertTableOfContents(tocswitches);
(build document here - includes headers)


Thanks for your inquiry. Please share document file to narrow down the problem. I will also suggest you to always use latest Aspose.Words for .NET.

Follow up the link to download latest Aspose.Words for .NET 10.8.0 :

Thanks for the reply - I have just tried with 10.8 and have the same issue (plus would need to mdify mail merge remove empty regions logic). I’ve attached the documents.

This doesn 't work.docx is the template document with the toc inserted into a table. I build my document from this document

Thisdoesntworkoutput.docx is the output after building the document and calling update fields.

Thisworks.docx is the template document with the toc not in a table. I build my document from this document

Thisworksoutput.docx is the output after building the document and calling update fields.
These two documents were generated int the exact same way - the only difference is that in the one that works the toc is NOT in a table. As you can see the toc in the working doc is nicely formatted with page numbers. The non-working doc loses all toc formatting and has no page numbers.

Just to clarify, in the output w/o page numbers the formatting is retained. It is just the page numbers that are missing. (When I save to pdf that is when the formatting gets lost but that is another issue).


Thanks for your inquiry. While using the latest version of Aspose.Words i.e. 10.8.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for inconvenience.

Moreover, as a work around, please try decreasing the distance between the left and right sides of TOC, e.g. you can reset the RightIndent to the width of container Cell as follows:

Document doc = new Document(@"C:\test\this doesnÆt work.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

string tocswitches = "\\o \"1-4\" \\h \\z \\u";
Field tocfield = builder.InsertTableOfContents(tocswitches);

// Get the container table cell
Cell tocCell = tocfield.Start.ParentNode.ParentNode as Cell;

Style toc1 = doc.Styles[StyleIdentifier.Toc1];
Style toc2 = doc.Styles[StyleIdentifier.Toc2];
Style[] tocStyles = { toc1, toc2 };
foreach (Style style in tocStyles)
    double leftIndent = style.ParagraphFormat.LeftIndent;
    style.ParagraphFormat.LeftIndent = leftIndent;
    style.ParagraphFormat.TabStops.Add(tocCell.CellFormat.Width - 10, TabAlignment.Right, TabLeader.Dots);


I hope, this will help.

Best Regards,

Thanks for the quick reply and workaround. I had to change the code slightly and modify the template a bit but the workaround solved my immediate problem - thanks!
Any idea when this defect might be fixed? In our product, we allow the users to modify the templates. It’s possible that this workaround might not work in every situation.

Hi Debra,
Thanks for your inquiry. Unfortunately, the issue is still pending for analysis. Once our developers analyze the issue, we will be able to provide you an estimate.
Sorry for inconvenience.

Hi Debra,

Thanks for your patience. It is to update you that our development team has finished working on your issue (WORDSNET-5688) and has come to a conclusion that your issue and the behaviour you’re observing is actually not a bug in Aspose.Words. So, we’ve closed this issue as ‘Not a Bug’. If we can help you with anything else, please feel free to ask.

Best Regards,

The issues you have found earlier (filed as WORDSNET-5688) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.