Check if TOC is empty

When creating a table of Figures and using this call: 

figuresTOC.TableOfFiguresLabel = "Figure ";

After calling UpdateDocumentFields, is there a way to check if there are any items in the Table of Figures, and to remove the table if there are no items? 


6 Replies

SB Sneha Biju Syncfusion Team June 7, 2024 08:05 AM UTC

Hi Natalie,

Based on the information provided, we have found that your requirement is to remove the Table of Figures from the Word document if there are no records in it. We have prepared a sample to fulfill your requirements, which is attached below.

In the sample, we followed the following steps:
1. Open the existing Word document that contains Table of Figures
2. Update the document fields
3. Retrieve the Table of Figures from the Word document
4. Remove the Table of Figures if there are no items in it
5. Save the Word document.

During the removal process, we followed these steps:
1. Iterate through the items from the Table of Figures, starting from the first item to the last item.
2. Obtain the list of text ranges in each paragraph
3. When reaching the last item, check if the list of texts contains any values in the Table of Figures. If not, return null; otherwise, return the last item.
4. If the last item is obtained, add a bookmark at the beginning and end of the Table of Figures.
5. Delete the content within the bookmark.

Regards,
Sneha.


Attachment: RemoveemptyTableofFigures_1888b8aa.zip


NW Natalie Westphal June 11, 2024 08:12 PM UTC

Is it possible to simply expose the TOCEntryEntities property on TableOfContent to just check the entity count? That is a crazy amount of code, in my opinion, to simply check if any items exist in the table of contents and then to delete the whole thing. 


Thanks,

Natalie



SB Suriya Balamurugan Syncfusion Team June 12, 2024 02:34 PM UTC

Natalie,

We will check the feasibility of your requirement and share you the further details on 14th June, 2024.



DA Dharanitharan Ayyasamy Syncfusion Team June 14, 2024 03:12 PM UTC

Natalie, we have analyzed the feasibility to “Provide an API to get TableOfContent entries”. We have logged this as a feature request in our database. We don’t have any immediate plans to implement this feature. We will update you once this feature has been implemented.

The status of the feature report can be tracked through the below link:
https://www.syncfusion.com/feedback/58721/provide-an-api-to-get-tableofcontent-entry-items



NW Natalie Westphal July 29, 2024 06:23 PM UTC

Hello,

Instead of removing the table of contents, is it possible to check the last value of a FieldSequence with a certain label to see if any values exist before creating the TOC? 



DS Dharanya Sakthivel Syncfusion Team July 30, 2024 04:45 PM UTC

Natalie,

Based on the information provided, we found that your requirement is to check if the target caption matches in the document sequence field caption name and then create a TOC for the caption. To meet your requirement, we have prepared and attached a sample in the below attachment.

In the attached sample, we have done the following things:
1
Open an existing Word document and find all SEQ fields using FindAllItemsByProperty.
2.Iterate through all SEQ fields and compare the sequence caption name with the target caption.
3. If a match is found, create and append a Table of Figures.
4. Update the Table of Contents.
5. Save the document.

Kindly refer the below documentation and GitHub samples
Working-with-table-of-contents
GitHub-examples

Regards,
Dharanya.


Attachment: Checktargetcaptionpresentornot_6639da85.zip

Loader.
Up arrow icon