方式一
/**
* EXCEL转HTML
* @param xlsfile EXCEL文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public void excelToHtml(String htmlfile,String xlsfile) {
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
try {
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method, new Object[] { xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(44) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
app.invoke("Quit", new Variant[] {});
}
}
方式一可能出现以下问题错误,但是如果文档是纯文本的话可以考虑方式一。
方式二:
待更新