Hi,
I want to get a new Document with a dotx Word template (my file attached), but the StyleCollection doesn’t contain all of the word styles - e.g. it shows Heading 2, but doesn’t have Heading 1 or Heading 3. If you open the template, open some of these styles (e.g. Heading 1) and just press ok, then it will be included in the Document.Styles although there were no changes.
I can replicate this with the code below. If run before changes to the template, it will show:
Normal
Heading 2
Default Paragraph Font
Table Normal
No List
List Paragraph
Header
Header Char
Footer
Footer Char
Heading 2 Char
If run after opening Heading 1, Heading 3 and Heading 4 styles (just open and press ok), it will show:
Normal
Heading 1
Heading 2
Heading 3
Heading 4
Default Paragraph Font
Table Normal
No List
List Paragraph
Header
Header Char
Footer
Footer Char
Heading 2 Char
Heading 1 Char
Heading 3 Char
Heading 4 Char
The code to replicate the issue:
Document doc = new Document(@"TemplateForAspose.dotx");
StyleCollection styles = doc.Styles;
for (int i = 0; i < styles.Count; i++)
{
Console.WriteLine(styles[i].Name);
}
Could you please advise how I can get the access to the all Word Styles from my template but without opening them manually in Word?
Thanks
DominikaTemplateForAspose.docx (16.2 KB)