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

Free Support Forum - aspose.com

Build TOC based on custom styles

I have been trying Aspose.Words for java to add a TOC with Custom Style. The custom style is built as a copy of the standard Heading Styles as below:

Style newStyle;
for(int i=1;i<=9;i++){
newStyle = doc.getStyles().addCopy(doc.getStyles().get("Heading "+i));
newStyle.setName(“SecTitle”+i);
newStyle = doc.getStyles().addCopy(doc.getStyles().get("Heading "+i));
newStyle.setName(“ClauseTitle”+i);
}

But my TOC shows all the standard styles and custom styles also in the document.
Tried with builder.insertTableOfContents("\o “1-9” \t “SecTitle1” “); and
builder.insertTableOfContents(”\h \z \t “SecTitle1,1” ");

Please let me know how do I ensure the TOC is built only for custom styles SecTitle1 - SecTitle9 and ClauseTitle1 - ClauseTitle9 and no heading styles are displayed in the TOC.

Thanks,
Kundana.

@Kundana

Thanks for your inquiry. You need to insert custom styles in the TOC field codes. The field codes should be like { TOC \h \z \t “Style1,1,Style2,2” }. The “Style 1” and “Style 2” are custom styles.

If you face any issue, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.