Control Include Label and Number Option of Table of Figures in Word DOCX Document using C# .NET

Hi Team,

We are using the Aspose library to generate the Word Doc and PDF. We generating Table of Content and Table of Figures in this. Table of Content is generating properly but if you see the Table of Figure then it’s having extra unwanted numbering. Please see the below screenshots. I have highlighted the unwanted numbering with yellow.

TOC.PNG (20.0 KB)

TOF.PNG (26.3 KB)

We have folloing code:

Table of Content:

//Insert TOC with only H2 (one Level)
var switches = "\\o \"2-2\" \\h \\z \\u";
builder.InsertTableOfContents(switches);

Table of Figures:

builder.InsertTableOfContents("\\h \\z \\c \"Figure\"");

Please suggest that how can we remove highlighted numbering from the Table of Figures.

Thanks,
Kushal

@kushalpaliwal847,

Please compress the following resources into ZIP format and attach the .zip file here for testing:

  • A simplified source Word document you are getting this problem with
  • Aspose.Words generated output Word and PDF files showing the undesired behaviors
  • Your expected Word DOCX file showing the desired output. You can create this file manually by using MS Word.

As soon as you get these pieces of information ready, we will then start further investigation into your particular issue and provide you more information.

Hi @awais.hafeez

Please find attached the ZIP for asked resources. I have already shared the line of codes in my initial description of the issue. We are using the same code to generate the table of content and the table of figures.

I got the expected behaviour in MS word by unchecking the “include label and number” checkbox in the table of figure dailogebox. I have attached the screenshot of the same for reference. We want to achieve the same by code.

Resources.zip (3.7 MB)
TOF in Word.png (69.8 KB)

Please investigate and share the inputs to get the expected result.

Thanks,
Kushal

@kushalpaliwal847,

You can use \a switch to generate table of figures without additional numbering. Please try the following code:

Document doc = new Document("C:\\Temp\\Resources\\Output Word.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertTableOfContents(" \\h \\z \\c \"Figure\" ");
builder.Writeln();
builder.InsertTableOfContents(" \\h \\z \\a \"Figure\" "); // Omit Additional Numbering

doc.UpdateFields();
doc.Save("C:\\temp\\Resources\\21.6.docx");

@awais.hafeez- I have tried with your inputs. Now we are not getting extra numbering but we are getting extra DOT. Please see the table of figures section of the attached output docx. I am using the same input file and the following line of code to generate a table of figures section.

builder.InsertTableOfContents(" \\h \\z \\a \"Figure\" ");

New Output Word.docx (693.8 KB)

@kushalpaliwal847,

We have logged your requirement/problem in our issue tracking system. Your ticket number is WORDSNET-22438. We will further look into the details of this issue and will keep you updated here on the status of the linked ticket. We apologize for your inconvenience.

@awais.hafeez,

Is it possible to you to provide a high-level ETA for WORDSNET-22438. So that we can communicate same to business same.

Thanks,
Kushal

@kushalpaliwal847,

WORDSNET-22438 is currently pending for analysis and is in the queue. There are no estimates available at the moment. Once the analysis of this issue is completed and the root cause is determined, we may then be able to calculate and share the ETA of this issue with you. We apologize for any inconvenience.

The issues you have found earlier (filed as WORDSNET-22438) have been fixed in this Aspose.Words for .NET 21.8 update and this Aspose.Words for Java 21.8 update.

@awais.hafeez

Hope you are doing good. Seems like WORDSNET-22438 is fixed with the current relase. Could you help me with the documentation to fix my issue?

Thanks,
Kushal

@kushalpaliwal847,

We have fixed the above problem in 21.8. Please try running the same code from my previous post. I have attached the output here for your reference: