您好,我在参考文档进行文档合并时使用了如下代码,两个文档中均有相同样式(标题一)的编号(2.docx由1.docx复制得到);此时合并的文档中的编号并没有继续编号而是重新开始。类似于如下格式,请问如何操作能够使得拼接上去的内容能够从4继续编号呢
1. 二
2. 三
3. 四
1. 二………………
public static void main(String[] args) throws Exception{
//创建两个Document对象并加载两个示例文档
Document document1 = new Document("D:\\1.docx");
Document document2 = new Document("D:\\2.docx");
//遍历第二个文档,获取所有节
for (Object sectionObj : document2.getSections()) {
Section sec=(Section)sectionObj;
//遍历第二个文档的所有节,获取其子对象
for (Object docObj : sec.getBody().getChildObjects()) {
DocumentObject obj=(DocumentObject)docObj;
//获取第一个文档的最后一节
Section lastSection = document1.getLastSection();
//lastSection = document1.getSections().get(1);
//将子对象添加到第一个文档的最后一节中
Body body = lastSection.getBody();
body.getChildObjects().add(obj.deepClone());
}
}
//String listText = paragraph.getListText();
//保存结果文档
document1.saveToFile("result2.docx", FileFormat.Docx);
}