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

Free Support Forum - aspose.com

Changing default TOC styles in AllStyles2007.docx

Hi,


I want to change the default built-in styles in AllStyles2007.docx for StyleIdentifier.TOC1 and other TOC headings.

Currently styles are :

<w:style w:styleId=“TOC1” w:type=“paragraph”>
<w:name w:val=“toc 1”/>
<w:basedOn w:val=“Normal”/>
<w:next w:val=“Normal”/>
<w:autoRedefine/>
<w:rsid w:val=“00805BCE”/>
</w:style>

I want to change it to:

<w:style w:styleId=“TOC1” w:type=“paragraph”>
<w:name w:val=“toc 1”/>
<w:basedOn w:val=“Normal”/>
<w:next w:val=“Normal”/>
<w:autoRedefine/>
<w:uiPriority w:val=“39”/>
<w:unhideWhenUsed/>
<w:rsid w:val=“00701AA6”/>
<w:pPr>
<w:spacing w:after=“100”/>
</w:pPr>
</w:style>

So that whenever TOC is used document updated TOC styles are used. I want to change it in AllStyle2007.docx , not in the current document where TOC is used, so that any document I create using aspose I used updated style.
Is there any way I can achieve it?

Thanks
Shubhangi

Hi,


I want to change the default built-in styles in AllStyles2007.docx for StyleIdentifier.TOC1 and other TOC headings.

Currently styles are :

<w:style w:styleId=“TOC1” w:type=“paragraph”>
<w:name w:val=“toc 1”/>
<w:basedOn w:val=“Normal”/>
<w:next w:val=“Normal”/>
<w:autoRedefine/>
<w:rsid w:val=“00805BCE”/>
</w:style>

I want to change it to:

<w:style w:styleId=“TOC1” w:type=“paragraph”>
<w:name w:val=“toc 1”/>
<w:basedOn w:val=“Normal”/>
<w:next w:val=“Normal”/>
<w:autoRedefine/>
<w:uiPriority w:val=“39”/>
<w:unhideWhenUsed/>
<w:rsid w:val=“00701AA6”/>
<w:pPr>
<w:spacing w:after=“100”/>
</w:pPr>
</w:style>

So that whenever TOC is used document updated TOC styles are used. I want to change it in AllStyle2007.docx , not in the current document where TOC is used, so that any document I create using aspose I used updated style.
Is there any way I can achieve it?

Thanks
Shubhangi


Hi Shubhangi,

Thanks for your inquiry. You can update styles of AllStyles2007.docx by creating empty document and update its styles as shown below. After updating style, append your document to empty document. Hope this helps you.

Document template = new Document();
Style toc1 = template.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_1);
toc1.getFont().setSize(10);
toc1.getFont().setName("Arial");
toc1.getFont().setColor(Color.RED);
//Your code...


Document doc = new Document(MyDir + "input.docx");
template.removeAllChildren();
template.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
//Your code...
template.setAutomaticallyUpdateSyles(true);
template.save(MyDir + "output.docx");