How can I get styles of default style of a document

Hi guys,


I quite new to the aspose word and currently working with the aspose word product, I am working with a task that load a template and use it to export content to a new document. But I need to get styles of default style set of a document (styles in image bellow) so that I can guide the service to chose the correct style from the template when exporting.

After I load a template, I use doc.Styles to get all style from document but it has a lot of duplicate styles and I do not know how to filter to get the style from this picture.

My current aspose version is 14.4.0.0.

Image and video hosting by TinyPic

Hi Thinh,


Thanks for your inquiry. If you
want to iterate through only unique styles in a document, it must use
the “for” statement instead of “foreach”. Please check the following code example for your kind reference.

Document doc = new Document(MyDir

  • “in.docx”);

StyleCollection styles = doc.Styles;

for(int i = 0; i < styles.Count;i++)

{

Console.WriteLine(styles[i].Name);

}


Moreover, please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting
1) to Run nodes by using Character Styles e.g. a Glyph Style
2) to the parent of those Run nodes i.e. a Paragraph node (possibly via paragraph Styles)
3) you can also apply direct formatting to Run nodes by using Run attributes (Font). E.g if you apply Garamond, 10pt to some text, you can use Run.Font.