文档A中有段落编号,将文档B插入文档A的书签处,并有一个正确的段落编号该怎么实现新建 DOCX 文档.docx (62.7 KB)
@qiiiii, 您可以使用以下 API 执行此操作:
这是示例:
public static void main(String[] args) throws Exception {
License lic = new License();
lic.setLicense("Aspose.Words.Java.lic");
Document docA = new Document("文档A.docx");
DocumentBuilder b = new DocumentBuilder(docA);
// Find and remember the list in 文档A.
List docAList = null;
Iterable<Paragraph> paras = docA.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : paras) {
if (para.isListItem()) {
docAList = para.getListFormat().getList();
break;
}
}
b.moveToBookmark("Bookmark1");
// Insert 文档B into 文档A.
Document docB = new Document("文档B.docx");
Node node = b.insertDocument(docB, ImportFormatMode.USE_DESTINATION_STYLES);
// Move to the first node of 文档B inside 文档A.
b.moveTo(node);
// The current node is the list paragraph.
Paragraph para = b.getCurrentParagraph();
while (para.isListItem())
{
// Assign the list from the 文档A to the list paragraphs inserted from 文档B.
para.getListFormat().setList(docAList);
para = (Paragraph)para.getNextSibling();
if (para == null)
break;
}
docA.save("merged.docx");
}