We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Table of Contents with custom header styles


I would like to insert a table of contents that ignores all standard header styles ("Heading 1", "Heading 2" etc) and instead picks on two custom header styles ("My Heading 1" & "My Heading 2").

This is because I am loading a number of documents into one document and I want to add a table of contents that lists out the documents, while ignoring any content within the loaded documents.

Many thanks, Paul.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can use the following code to insert TOC, which uses custom styles:

Document doc = new Document(@"Test001\in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

// Insert TOC, which uses custom styles.

builder.InsertTableOfContents("\\h \\z \\t \"My Heading 1;1;My Heading 2;2\"");

// Update TOC.



// Save the result.


Hope this helps.

Best regards.

Fabulous - thanks.

Great reply - thanks. However - I also need to ignore the standard header styles in this table of contents - do you know how I could do this.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. TOC like the following does not include items of standard heading styles, but only custom headings, i.e. “My Heading 1” as the first level and “My Heading 2” as the second level.

{ TOC \h \z \t "My Heading 1;1;My Heading 2;2" }

Please let me know if you have problems with this, I will be glad to help you. Also would be great if you attach your documents and code, which will allow me to reproduce the problem.

Best regards.