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

Free Support Forum - aspose.com

What is the strategy of auto creation build in style

I use Document.Styles[StyleIdentifier] to access styles, but the format of auto created style is different with which in MS word, so I want to konw the creation strategy of build in style, and how can i know that if the style is auto created or in document already.

@qingyuan.ni,

Thanks for your inquiry. The Style.BuiltIn property returns true if this style is one of the built-in styles in MS Word.

Please ZIP and attach your input Word document here for our reference. Please also share some more detail about your query what exact you want to achieve using Aspose.Words. We will investigate the issue on our side and provide you more information.

@tahir.manzoor

I tried to get Heading1 style from blank.docx, and the result indicates that the font size is 14 and bold, but I opened the document in ms word, and right clicked on Heading1 style and clicked modify, the display font size is 16 and not bold. And there are other differences between the result of aspose and ms word
below is the code:
var document = new Document(@“D:\blank.docx”);
var style = document.Styles[StyleIdentifier.Heading1];

I unzipped the file, and opened it’s styles.xml, found that there is no Heading1Char defined in it. and I noticed that the remark of Styles[“name”] said: If this is an English name of a built in style that does not yet exist, automatically creates it. so I think the return value of document.Styles[StyleIdentifier.Heading1] maybe created by aspose.

it’s perfect if the result can be same with which in ms word, if cannot, i hope to know if the style is come from styles.xml or created by aspose.

the zipped document file:blank.zip (8.9 KB)

@qingyuan.ni,

Thanks for your inquiry.

Your understanding is correct. If the “Heading 1” style does not exist in Word document and you access it using Document.Styles[StyleIdentifier.Heading1], it will be created by Aspose.Words. You can change the font size of style using following code snippet.

var style = document.Styles[StyleIdentifier.Heading1];
style.Font.Size = 16;

There is a lot of styles listed in StyleIdentifier enum; however, these all styles are not required to be embedded in the document. MS Word creates these styles when it is necessary. The main purpose of StyleIdentifier is language independence i.e. the names of built-in styles in MS Word are localized for different languages and using a style identifier you can find the correct style regardless of the document language.

@tahir.manzoor

so, how to known that the style is created by Aspose.Words or embedded in the document? I need to update the styles which Aspose.Words created, they are not as same as which in MS Word

@qingyuan.ni,

Thanks for your inquiry. You can check either a style exists in the document or not using following code example.

int styleCount = document.Styles.Cast<Style>().ToList().Where(style => style.Name == "Heading 1").ToList<Style>().Count;
if (styleCount == 0)
    Console.WriteLine("Style does not exist.");

If a style does not exist in the document, you can create it as shown below.

var style = document.Styles[StyleIdentifier.Heading1];
style.Font.Size = 16;

I got it, thanks

@qingyuan.ni,

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