51,408
社区成员
发帖
与我相关
我的任务
分享public static void docToHtml(String docfile,String htmlfile) {
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
try {
app.setProperty("Visible", new Variant(false));
// 设置word不可见
Object docs = app.getProperty("Documents").toDispatch();
Object doc = Dispatch.invoke(
(Dispatch) docs,
"Open",
Dispatch.Method,
new Object[] { docfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
// 打开word文件
Dispatch.invoke((Dispatch) doc, "SaveAs", Dispatch.Method,
new Object[] { htmlfile, new Variant(8) }, new int[1]);
// 作为html格式保存到临时文件
Variant f = new Variant(false);
Dispatch.call((Dispatch) doc, "Close", f);
} catch (Exception e) {
logger.info("docToHtml error :" + e.getMessage());
e.printStackTrace();
} finally {
app.invoke("Quit", new Variant[] {});
}
}