@Bips,
Each section in Word document is represented by a Section object that can be obtained from the Document.Sections collection by the index. The following Java code deep clones a Section and inserts it right after the original Section:
Document doc = new Document("C:\\temp\\input.docx");
Section section = doc.getSections().get(0); // use any index
Section cloneOfSection = (Section) section.deepClone(true);
doc.insertAfter(cloneOfSection, section);
doc.save("C:\\temp\\awjava-20.11.docx");
You can also find Section of a particular list item and clone it by using the following code:
Document doc = new Document("C:\\temp\\list.docx");
doc.updateListLabels();
Paragraph targetPara = null;
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.isListItem() & para.getListLabel().getLabelString().equals("1.2.1")) {
targetPara = para;
}
}
if (targetPara != null) {
Section section = (Section) targetPara.getAncestor(NodeType.SECTION);
Section cloneOfSection = (Section) section.deepClone(true);
// Lets insert after the original section
doc.insertAfter(cloneOfSection, section);
}
doc.save("C:\\temp\\awjava-20.11.docx");
If this is not what your requirement is, then please provide the resources which were requested in my previous post. We will then investigate the scenario/issue on our end and provide you code to achieve the same output by using Aspose.Words.