I am using Aspose Words Java API to move content from one document to another. The source document contains numbered-list items. When the list items are copied to the target document, the sequence no for all items in the list are changed to 1 instead of (1, 2, 3, 4…).
For reference, I am attaching the sample input document: “aspose_number_list_input.docx” and output document.
Here is the code sample:
Document targetDocument = new Document(“output.docx”);
Document sourceDoc = new Document(“aspose_number_list_input.docx”);
// Used Aspose examples code as reference
Node targetStartNode = paragraphsByTitleName(targetDocument, targetNodeStyle, targetNodeHeading);
Node startNode = paragraphsByTitleName(sourceDoc, sourceDocNodeStyle1, sourceDocNodeText);
Node endNode = paragraphsByTitleName(sourceDoc, sourceDocNodeStyle1, sourceDocNodeText);
List tempnodes = extractContent(startNode, endNode, ); // Extract list of paragraphs between 2 nodes in source document
// Importing paragraph nodes and inserting into target document
for (Node newNode : tempnodes) {
Node updNode = targetDocument.importNode(newNode, true);
targetStartNode.getParentNode().insertAfter(updNode,targetStartNode);
targetStartNode = updNode;
}
targetDocument.save(“output.docx”);