有需要的可以将主函数中写死的地方改为一个List。
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
public class MergeDoc {
public static void main (String[] args) throws Exception {
InputStream in1 = null;
InputStream in2 = null;
OPCPackage src1Package = null;
OPCPackage src2Package = null;
OutputStream dest = new FileOutputStream("dest.docx");
try {
in1 = new FileInputStream("/Users/liuyahui/test.docx");
in2 = new FileInputStream("/Users/liuyahui/test1.docx");
src1Package = OPCPackage.open(in1);