Unmodified "Heading 1" style not retrievable from document

Hi,

We have some issues retrieving standard Word styles (in this example “Heading 1”) in a document. But if we modify this style it becomes retrievable.
For reproducing this issue please use the attached files (in 1.docx the style is not modified, in 2.docx the style is modified) and the following code:

//Unused Unmodified Heading1 Style Is Not Retrieved
var document = new Document(“1.docx”);
var heading1Style = document.Styles.Cast().FirstOrDefault(x => x.Name == “Heading 1”);

if (heading1Style == null)
Console.WriteLine(“Unmodified Heading 1 style is not retrieved.”);

//Unused Modified Heading1 Style Is Retrieved
document = new Document(“2.docx”);
heading1Style = document.Styles.Cast().FirstOrDefault(x => x.Name == “Heading 1”);

if (heading1Style != null)
Console.WriteLine(“Modified Heading 1 style is retrieved.”);


Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi Aurelian,


Thanks for your inquiry. The problem occurs because there is no text in “1.docx” document which is formatted with “Heading 1” style i.e. this style is not used in this document. The following code could also not find this style in document.
foreach (Style s in doc.Styles)
Console.WriteLine(s.Name);
Moreover, you can verify by unzipping the document and check styles.xml, there is no “Heading 1” style in it. So, this is the expected behavior.

Best regards,

Hi Awais,

Yes that is correct, “Heading 1” style is not used in these documents, still in the second document (“2.docx”) this style is retrieved. Basically even if “Heading 1” style is not used in the files I sent, it is retrieved in “2.docx” (where this style is customized) but it’s not retrieved in “1.docx” (where this style is not customized).

Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi Aurelian,


Thanks for your inquiry. Please unzip 2.docx document and check styles.xml, there you’ll find “Heading 1” style in it. That is why Aspose.Words is able to read this style from styles.xml.

Best regards,