Free Support Forum - aspose.com

Hello,

I am parsing the toc of a document, and I am doing this paragraph by paragraph. What I need is to get for each toc entry( paragraph) the information related to the range of that entry.

For instance, if I have something like this:
Introduction…1
Scope, Approach and Methods… 2
Information Sources…4
Etc.
How can I say “Introduction…1” has range 1 and “Information Sources…4” has range 2?

Thanks,
Mircea

Hello

Thanks for your request. I think in this case you can try using the following code:

// Open document

Document doc = new Document("C:\\Temp\\in.docx");

// Get all paragraphs

NodeCollection nodeColl = doc.getChildNodes(NodeType.PARAGRAPH, true);

// Loop through all paragraphs

for(int i = 0; i < nodeColl.getCount(); i++){

switch (((Paragraph)nodeColl.get(i)).getParagraphFormat().getStyleIdentifier())

{

System.out.println(((Paragraph)nodeColl.get(i)).toTxt() + "Range 1");

break;

System.out.println(((Paragraph)nodeColl.get(i)).toTxt() + "Range 2");

break;

System.out.println(((Paragraph)nodeColl.get(i)).toTxt() + "Range 3");

break;

default:

// do nothing.

break;

}

}

Bets regards,

Hi there,