// 文件预览 excel转为html
public String doviewFile() throws IOException {
File excelFile = new File("\\\\10.20.127.161\\html\\WebReport\\tempdir\\Lesson Learnt.xlsx");
File htmlFile = new File("\\\\10.20.127.161\\html\\WebReport\\Lesson Learnt.html");
ComThread.InitSTA();
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动Excel
System.out.println("java.library.path:"+System.getProperty("java.library.path"));
try {
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { excelFile.getAbsolutePath(), new Variant(false),new Variant(true) },new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlFile.getAbsolutePath(), new Variant(44) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
} catch (Exception e) {
lg.info("转html报错"+e.toString());
e.printStackTrace();
} finally {
app.invoke("Quit", new Variant[] {});
}
//释放com线程
ComThread.Release();
return "html文件转换成功";
}
excel转为html代码
最新推荐文章于 2024-03-07 16:56:56 发布