Get Editable Regions' Content from Word Document using Java

Can you please help with the code to find the editable regions of a word document using Aspose for Java?

@yalshaiba,

Editable ranges in Word document are represented by EditableRangeStart and EditableRangeEnd classes in Aspose.Words’ DOM (document object model). All the nodes in-between a EditableRangeStart and a related EditableRangeEnd nodes belong to same Editable range. Please check the following Java code to find EditableRangeStart and related EditableRangeEnd nodes from Word document:

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

for (EditableRangeStart start :
        (Iterable<EditableRangeStart>) doc.getChildNodes(NodeType.EDITABLE_RANGE_START, true)) {
    EditableRangeEnd end = start.getEditableRange().getEditableRangeEnd();

    // and the code to find the nodes belonging to this editable range is
    Node currentNode = start;
    while (currentNode != null && currentNode != end) {
        Node nextNode = currentNode.nextPreOrder(currentNode.getDocument());

        if (nextNode.getNodeType() == NodeType.RUN)
            System.out.println(((Run) nextNode).getText());

        currentNode = nextNode;
    }
}

Thank you. This code does the job neat!

1 Like