Get last bullet no from a Structured Document Tag

I am using Java API for Aspose.words and I have aspose jar 20.12. Using that jar I want to get last bullet no in a StructuredDocumentTag.

I have used builder.ListFormat.ListLevelNumber, getListFormat().getList().getListLevels and paragraph.getListFormat().getListLevelNumber() but I got no success

@muniryousafzai Do you need the actual list label of the paragraph? If so, you should first call Document.updateListLabels method and then using Paragraph.ListLabel property:

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

// Get SDT
StructuredDocumentTag sdt = (StructuredDocumentTag)doc.getChild(NodeType.STRUCTURED_DOCUMENT_TAG, 0, true);
// Get the last paragraph in the SDT.
// NOTE it is supposed that SDT is on the block level.
Paragraph p = (Paragraph)sdt.getLastChild();
System.out.println(p.getListLabel().getLabelString());

@alexey.noskov It didn’t worked. So I initialized a “count” variable and incremented it in Paragraph loop under the condition if paragraph is list item then increment the “count” variable

@alexey.noskov Can you please answer another query, I want to continue numbering of a list in StructureDocumentTag from the last bullet of previous StructureDocumentTag. e.g. if we have last bullet 6 for a list(which is actually in StructureDocumentTag) then the next list in new StructureDocumentTag should start from 7.

@muniryousafzai There are two options to continue numbering in two lists.

in.docx (13.9 KB)

  1. You can make the items in both lists belong to the same list. For example, in the attached input document there are two lists. Using the following code we make all list items to belong to the same list and numbering is continued.
Document doc = new Document("C:\\Temp\\in.docx");
com.aspose.words.List lst = null;
for (Paragraph p : doc.getFirstSection().getBody().getParagraphs())
{
    if (p.isListItem())
    {
        if (lst == null)
            lst = p.getListFormat().getList();

        if (p.getListFormat().getList() != lst)
            p.getListFormat().setList(lst);
    }
}
doc.save("C:\\Temp\\out.docx");

out.docx (11.4 KB)

  1. You can specify ListLevel.StartAt property of the second list:
Document doc = new Document("C:\\Temp\\in.docx");
com.aspose.words.List lst = null;
int lstItem = 0;
for (Paragraph p : doc.getFirstSection().getBody().getParagraphs())
{
    if (p.isListItem())
    {
        if (lst == null)
            lst = p.getListFormat().getList();
        lstItem++;

        if (p.getListFormat().getList() != lst)
        {
            p.getListFormat().getListLevel().setStartAt(lstItem);
            break;
        }
    }
}
doc.save("C:\\Temp\\out.docx");

out.docx (11.4 KB)