以下为合并Word主要代码部分
public static void docMerge(List<String> fileList, String savepaths) {
if (fileList.size() == 0 || fileList == null) {
return;
}
// 判断文件是否存在
if( new File(savepaths).exists() ){
try {
new File(savepaths).delete();
new File(savepaths).createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
}
/** 01.创建一个word **/
//打开word
ActiveXComponent word = new ActiveXComponent("Word.Application");
// 设置word不可见
word.setProperty("Visible", new Variant(false));
//获得documents对象
Dispatch dstDoc = word.getProperty("Documents").toDispatch();
/** 02.填充待合并的word到目标word **/
Dispatch doc = Dispatch.call(dstDoc, "Add").toDispatch();
Dispatch sel = word.getProperty("Selection").toDispatch();