/*** 文档转换函数** @param docfile* word文档的绝对路径加文件名(包含扩展名)* @param htmlfile* 转换后的html文件绝对路径和文件名(不含扩展名)*/public static void change(String docfile, String htmlfile) {ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动wordtry {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) {e.printStackTrace();} finally {app.invoke("Quit", new Variant[] {});}}在用main函数测试时没有发现问题,但在实际调用时报错:C:\WINDOWS\system32\jacob.dll already loaded in another classloader或com.jacob.com.ComFailException: Invoke of: OpenSource: Microsoft WordDescription:这是为什么呢
- 2 回答
- 0 关注
- 189 浏览
添加回答
举报
0/150
提交
取消