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

Free Support Forum - aspose.com

How to modify default styles?

I'd like to know how I can modify the font setting of default Heading styles.

Thank you.

Hi there,


Thanks for your inquiry. Following code snippets shows how to change the font formatting of styles in a document. Hope this helps you. Please let us know if you have any more queries.

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”>Document doc = new
Document();<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue;mso-fareast-language:EN-GB”>foreach<span style=“font-size:
10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”> (Style style in
doc.Styles)<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”>{<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”> if (style.Font != null)<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”> {<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”>
style.Font.ClearFormatting();<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”>
style.Font.Size = 20;<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”>
style.Font.Name = “Arial”;<o:p></o:p>

<span style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
mso-fareast-language:EN-GB”> }<o:p></o:p>

}

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Style style = doc.Styles[StyleIdentifier.Heading1];

style.Font.ClearFormatting();

style.Font.Size = 15;

style.Font.Color = Color.Blue;

style.Font.Name = "Arial";

builder.ParagraphFormat.Style = style;

builder.Writeln("Hello World");

doc.Save(MyDir + "out.docx");


That worked great. Thank you.

Hi there,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.