Set paragraph/character format of table and figure table of contents

Hello, 

Can you please tell me how to set the paragraph style and character format of a table of contents created for figures or tables? 

This is the code I am using currently: 

var figuresTocParagraph = tocSection.AddParagraph();

figuresTocParagraph.AppendText("List of Figures").ApplyCharacterFormat(format);

figuresTocParagraph = tocSection.AddParagraph();

TableOfContent figuresTOC = figuresTocParagraph.AppendTOC(1, 3);

figuresTOC.UseHeadingStyles = false;

figuresTOC.TableOfFiguresLabel = "Figure ";


I am also using this code to set the general table of contents styles but I cannot find where to apply this format to the other table of contents: 

            for (int i = 0; i < headingDepth; i++)

            {

                var tocstyle = document.AddParagraphStyle("TOC " + headingDepth.ToString());

                tocstyle.CharacterFormat.FontName = "Arial";

                tocstyle.CharacterFormat.FontSize = 12;

            }


thanks. 


6 Replies 1 reply marked as answer

DS Dharanya Sakthivel Syncfusion Team June 4, 2024 12:55 PM UTC

Hi Natalie,

Based on the information provided, we have determined that your requirement is to set the paragraph or character format style to the TOC entries.

We can achieve this by
customize the TOC entries style in Word document. You can refer the below link:
How to customize the TOC entries style in Word document? (syncfusion.com)

For more information about Table of content, please refer to the documentation below:
Working with Table of Contents (TOC) | DocIO | Syncfusion

Regards,
Dharanya.




NW Natalie Westphal June 4, 2024 04:34 PM UTC

Thanks for your quick reply. I have been using the code: 

 var tocstyle = document.AddParagraphStyle("TOC 1"); 

to set the style of the TOC as shown in the documentation. However, these formats are not applied to the Table of Figures or Table of Tables. 

Is there a specific name of the paragraph style that I should be using in order to apply these? 



DS Dharanya Sakthivel Syncfusion Team June 5, 2024 09:56 AM UTC

Natalie, based on the information provided, we have determined that your requirement is to apply specific formatting to the table of figures and table of tables. We have created a sample to meet your requirement.

We have created a separate method to apply styles for the table of figures and table of tables.

The sample we have provided follows these steps:
1. Inside the TableOfFigure method, create a Word document.
2. Add sections and paragraphs in the document.
3. Add an image to the paragraph.
4. Add a caption to the image.
5. Access the Table of Figures style and update its formatting.
6. Update the table of contents.
7. Save the file in the given path.

1. Inside the TableOfTable method, create a Word document.
2. Add sections and paragraphs in the document.
3. Add a table into the Word document.
4. Add a sequence field to the table.
5. Update the fields in the Word document.
6. Access the Table of Figures style and update its formatting.
7. Update the table of contents.
8. Save the file in the given path.

You can find the prepared sample in the attachment below.



Attachment: TableOfFiguresCustomizeTOFentriesstyle_4fe6be8.zip

Marked as answer

NW Natalie Westphal June 5, 2024 05:05 PM UTC

Is there a way to check if there are any items in the Table of Figures/Tables, and to remove the table if there are no items? 

I have some tables that do not have titles that I do not want to be included in the table of contents. 



DS Dharanya Sakthivel Syncfusion Team June 6, 2024 04:28 PM UTC

Natalie, we are currently reviewing the reported issue regarding checking for items in the Table of Figures/Tables and removing the table if there are no items. We will provide you with more details on 10th June 2024.



SB Sneha Biju Syncfusion Team June 7, 2024 07:58 AM UTC

Natalie, based on the information provided, we have found that your requirement is to remove the Table of Figures/Tables 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/Tables
2. Update the document fields
3. Retrieve the Table of Figures/Tables from the Word document
4. Remove the Table of Figures/Tables 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/Tables, 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/Tables. 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/Tables.
5. Delete the content within the bookmark.


Attachment: RemoveemptyTableofFiguresandTables_1cd6f310.zip

Loader.
Up arrow icon