使用jacob 合并excel
try {
String tempDir = System.getProperty("java.io.tmpdir");
ActiveXComponent excel = new ActiveXComponent("Excel.Application");
Dispatch workbooks = excel.getProperty("Workbooks").toDispatch();
Dispatch workbook = Dispatch.call(
workbooks,
"Open","master.xls" ).toDispatch();
Variant[] vargs = new Variant[copyFromFilesArray.length + 2];
vargs[0] = new Variant("Sheet1.CombineWorkbooks");
SequenceUUID oGeneration = SequenceUUID.getInstance();
String tempFile = tempDir + oGeneration.getUUID() + ".xls";
vargs[1] = new Variant(tempFile);
for (int i = 0; i < copyFromFilesArray.length; i++) {
vargs[i + 2] = new Variant(copyFromFilesArray[i]);
}
Dispatch.call(excel, "Run", vargs);
return tempFile;
} finally {
ComThread.Release();
}
本文介绍了一种使用Jacob库在Java中合并多个Excel文件的方法。通过创建Excel应用程序实例,并调用特定API,可以将多个Excel文件合并到一个主文件中。此过程包括打开主文件、准备临时文件以及通过参数数组传递所有要合并的文件。
866

被折叠的 条评论
为什么被折叠?



