We have unfortunately encountered a problem when dynamically adding (one or more) Tables of Content.
We have a template docx (see attachment) where we want six different ToC's (in one page), based on chapter numbers that are created dynamically. After adding all chapters, we have tried two ways to add the ToC's:
- Use the built-in functions of Microsoft Word to differentiate between the ToC's and, when everything is added, call UpdateTableOfContents()
- Use code to add a new ToC and call UpdateTableOfContents(nameOfToc)
Both ways result in the same; in every place a ToC should be displayed, it shows "TOC", but they are all defined as proper ToC's, although only one (the first one) is already defined as a ToC in the template. This means that when the result file (see attachment) is opened in Word, and all ToC's are updated (f.e. via ctrl-a, F9), all ToC's are properly generated. So, the basis is there and is correct, but the ToC's simply are not generated.
Calling the UpdateTableOfContents methods twice, or calling the parameterless method after calling the other UpdateTableOfContents method does not help.
We are using version 10.9.6 (latest stable) of Spire.Doc.
Any help, but especially a fix, would be greatly appreciated!
Code snippet for adding ToC via Spire.Doc functionalities:
- Code: Select all
private void AddTableOfContentsWithSwitch(Report report, string tocSwitch)
{
Document doc = (Document)report.Document;
TableOfContent toc = new TableOfContent(doc, tocSwitch);
report.AddBlankParagraph();
Paragraph p = (Paragraph)report.CurrentParagraph;
p.Items.Add(toc);
p.AppendFieldMark(FieldMarkType.FieldSeparator);
p.AppendText("TOC");
p.AppendFieldMark(FieldMarkType.FieldEnd);
doc.TOC = toc;
doc.UpdateTableOfContents(toc);
}
The tocSwitch contains f.e.
- Code: Select all
"{\\t \"MW_NH_Header_B, 1\"}"