public static void excelToHtml(String xlsfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent
("Excel.Application"); // 启动word
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(EXCEL_HTML) }, new int
[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}
}
这里面要用到Office主键,其实和word转换成html的也差不多,我在word已经附属过这里就不强调了。。