Free Support Forum - aspose.com

Remove an Item from a Table of Contents

Is is possible to auto generate a TOC in aspose word
then manually remove one or more items from the generated TOC?

If yes can i have some code to do this?

Thanks

Hi Nitin,


Thanks for your inquiry. For example, the Table of Content (TOC field) in the document (produced by using the code from here) is built based off the content that is formatted with Heading (1, 2, 3 and so on) styles. In this case, all you need is to find the required headings, remove them and in the end call the UpdateFields method to update the TOC field. This will remove the related item from the TOC. Please let me know if I can be of any further assistance.

Best regards,

I understand.

But what if I want to keep the headings in the document, just not want them

in the TOC, do i just set the style of these headings to something else?

How can I keep the headings but not include them in the TOC.

for example i have the following headings in my word doc.

Introduction <-- this is Heading 1
What you will Need <-- Heading 2
How to Select the Right Equipment <--Heading 2

Wine Making Part 1 <-- Heading 1

Wine Making Part 2 <-- Hreading 1

Now I ONLY want the following items in my TOC

Introduction
Wine Making Part 1
Wine Making Part 2

However, I do not want to remove these headings from my content, so if the user
browses through my document, he will still see all the headings in the content where they
should be.

Is this possible?

How do i achieve this?

Thanks

Thanks

Hi Nitin,


Thanks for your inquiry. The way the TOC table is built and displayed by Microsoft Word is controlled by the field switches. For example, to include only headings i.e. formatted with style Heading1 in TOC, you need to specify field code as follows:

builder.InsertTableOfContents("\o “1-1” \h \z \u");

I hope, this helps.

Best regards,