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

Free Support Forum - aspose.com

How can we apply some styling on dynamic Table of contents?

Hello,

We are currently using Aspose.Word 9.2.0.0 to generate word files and we encounter problems when trying to apply some basic styling (font name, font size) to our table of contents paragraph.

You'll find in attachment our code sample and a generated file example : Table of contents is ok but text formatting is Times new roman : all our text styles (bold, verdana font, etc...) are not used (as you can see, we tried differents solutions to force verdana font)

Could you help us ?

Many thanks for your hard work.

Sebastien.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. If you would like to configure how TOC appear in the document, you can easily achieve this by editing Toc1, Toc2…TocN styles. For example, see the following code:

// Open document.

Document doc = new Document(@"Test001\in.doc");

// To configure how TOC look in the document, you can edit Toc1, Toc2...TocN styles.

// To demonstate the technique let's configure the first 4 levels of TOC.

Style toc1 = doc.Styles[StyleIdentifier.Toc1];

Style toc2 = doc.Styles[StyleIdentifier.Toc2];

Style toc3 = doc.Styles[StyleIdentifier.Toc3];

Style toc4 = doc.Styles[StyleIdentifier.Toc4];

Style[] tocStyles = { toc1, toc2, toc3, toc4 };

foreach (Style style in tocStyles)

{

// Change font name and size.

style.Font.Name = "Arial";

style.Font.Size = 14;

}

doc.Save(@"Test001\out.doc");

Hope this could help you.

Best regards.

Thank you for the tip, I’ve successfully added styles to my TOC