How to get the numbering for a particular paragraph

HI Team,

We are using Aspose.Words for .Net.

Our word document has a list of paragraphs in this format below.

a. paragraph 1
b. paragraph 2
c. paragraph 3
d. paragraph 4
i. sub para1
ii. sub para2

e. paragraph 5

we are looping through all the paragraphs in this way :
NodeCollection nc = doc.GetChildNodes(NodeType.Paragraph,true);
foreach(Paragraph p in nc)
{
string text = p.GetText();
.
.
.
}

The problem is we are able to get the paragraph text like paragraph1, paragraph 2 and so on.
But we are unable to fetch the numbering.
Th expectation is that we need to get the para text in this way a. paragraph 1,b. paragraph 2 and so on.

Please let us know on how to solve get the para numbering along with the para text.

@balaji7,

Please try using the following code:

Document doc = new Document("E:\\temp\\in.docx");
doc.UpdateListLabels();

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.IsListItem)
    {
        Console.WriteLine(para.ToString(SaveFormat.Text));
    }
} 

For more details about Document.UpdateListLabels method, please refer to the following link:
Document.UpdateListLabels method

1 Like