I am trying to merge two .docx documents with NPOI(API for Microsoft documents written in C# .Net). But I could not find any tool to merge two .docx document together in NPOI. Is there any tool can perform like JAVA POI tool poi-tl and provide methods to merge two documents 's content together in sequence, keeping the style?
In JAVA POI, we can use poi-tl to merge two .docx documents. Here's the test code.
package com.mischen.mapreduce.wordcount;
import com.deepoove.poi.xwpf.NiceXWPFDocument;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* @ClassName TestMergeWord
* @Description DOTO
* @Author mischen
* @Date 2021/5/13 0013 23:16
* @Version 1.0
**/
public class TestMergeWord {
public static void main(String[] args) throws Exception{
NiceXWPFDocument main = new NiceXWPFDocument(new FileInputStream("C:\\Users\\Administrator\\Desktop\\PMP\\pmp记忆知识点.docx"));
NiceXWPFDocument sub = new NiceXWPFDocument(new FileInputStream("C:\\Users\\Administrator\\Desktop\\PMP\\zookpeer.docx"));
NiceXWPFDocument design = new NiceXWPFDocument(new FileInputStream("C:\\Users\\Administrator\\Desktop\\PMP\\设计模式.docx"));
// 合并两个文档
NiceXWPFDocument newDoc = main.merge(sub).merge(design);
// 生成新文档
FileOutputStream out = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\PMP\\new_doc.docx");
newDoc.write(out);
newDoc.close();
out.close();
System.out.println("合并word成功!");
}
}