资源说明:JACOB一个Java-COM中间件.通过这个组件你可以在Java应用程序中调用COM组件和Win32程序库。
示例代码:
/**
* 转换xls到pdf
* @param excelFile
* @param pdfFile
*/
public static void converExcelToPdf(String excelFile,String pdfFile){
ActiveXComponent app = new ActiveXComponent("Excel.Application");
try {
app.setProperty("Visible", false);
Dispatch workbooks = app.getProperty("Workbooks").toDispatch();
//打开文件
Dispatch workbook = Dispatch.invoke(workbooks, "Open", Dispatch.Method, new Object[] { excelFile, new Variant(false), new Variant(false) }, new int[3]).toDispatch();
//另存为文件
Dispatch.invoke(workbook, "SaveAs", Dispatch.Method, new Object[] {pdfFile, new Variant(57), new Variant(false), new Variant(57), new Variant(57), new Variant(false), new Variant(true),
new Variant(57), new Variant(true), new Variant(true), new Variant(true) }, new int[1]);
//关闭
Dispatch.call(workbook, "Close", new Variant(false));
} catch (Exception e) {
throw new SmileRunException("excel 转 pdf出错 excel:"+excelFile+",pdf:"+pdfFile,e);
} finally {
if (app != null) {
app.invoke("Quit", new Variant[] {});
}
}
}
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。