/*** 文檔轉(zhuǎn)換函數(shù)** @param docfile* word文檔的絕對路徑加文件名(包含擴展名)* @param htmlfile* 轉(zhuǎn)換后的html文件絕對路徑和文件名(不含擴展名)*/public static void change(String docfile, String htmlfile) {ActiveXComponent app = new ActiveXComponent("Word.Application"); // 啟動wordtry {app.setProperty("Visible", new Variant(false));// 設(shè)置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函數(shù)測試時沒有發(fā)現(xiàn)問題,但在實際調(diào)用時報錯:C:\WINDOWS\system32\jacob.dll already loaded in another classloader或com.jacob.com.ComFailException: Invoke of: OpenSource: Microsoft WordDescription:這是為什么呢
?在web項目下,用jacob實現(xiàn)將word文檔轉(zhuǎn)換為html格式的頁面,方法:
子衿沉夜
2022-11-04 17:13:03