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

Free Support Forum - aspose.com

Issues to Extract Content Based on Styles - Words for .net

Document Attached(TestStyle.docx) to show/use in the example..

Created a document with user defined styles (Refer document TestStyle.docx attached with styles:Topic Style, Question Style, Answer Style )

Trying to Read the style using the code as shown at the end of this post:

All the styles are considered as "Default Paragraph Text", Aspose is not recognizing the styles.

Sometime is does. It is not consistent. Am i doing something wrong?

Thanks in advance .

Code :

//Sample Code

//Calling the Method
ReadStyle(@"c:\Test\Teststyles.docx");

private Document ReadStyle(Document docforReadingStyles)
{
NodeCollection runs = docChangeStyles.GetChildNodes(NodeType.Run, true);
int CountTopics = 0;
int CountQuestions = 0;

// Loop through every run node.
foreach (Run run in runs)
{

if (run.Font.StyleName.Contains("Topic"))
{

CountTopics++;
}
if (run.Font.StyleName.Contains("Question"))
{
CountQuestions++;
}
}
}


This message was posted using Page2Forum (attachment) from Aspose.Words for .NET - Documentation

Hi

Thanks for your request. In your case, style is applied to paragraphs:

[Test]

public void Test001()

{

Document doc = new Document(@"Test001\Teststyle.docx");

doc.Accept(new StyleChecker());

}

private class StyleChecker : DocumentVisitor

{

public override VisitorAction VisitParagraphEnd(Paragraph paragraph)

{

Console.WriteLine(paragraph.ParagraphFormat.StyleName);

return base.VisitParagraphEnd(paragraph);

}

}

Best regards,

Hi Alexey,

It worked.

NodeCollection

runs = docChangeStyles.GetChildNodes(NodeType.Paragraph, true);

Appreicate your quick response.

Thanks