Home  >  Article  >  Web Front-end  >  Jacob方式将html静态页面导出生成word文档_html/css_WEB-ITnose

Jacob方式将html静态页面导出生成word文档_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:01:301547browse

摘要 这种方式的好处是生成的word文档 用office打开时默认是页面视图,而不会是web视图。
 /*************  * JACOB方式  * notes:需要将jacob.dll拷贝到windows/system32和classpath路径下  * @param html html静态页面路径  * @param wordFile 要生成的word文档路径  */ public static void htmlToWord(String html, String wordFile) {             ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word         try {             app.setProperty("Visible", new Variant(false));             Dispatch wordDoc = app.getProperty("Documents").toDispatch();             wordDoc = Dispatch.invoke(wordDoc, "Add", Dispatch.Method, new Object[0], new int[1]).toDispatch();             Dispatch.invoke(app.getProperty("Selection").toDispatch(), "InsertFile", Dispatch.Method, new Object[] { html, "", new Variant(false), new Variant(false), new Variant(false) }, new int[3]);             Dispatch.invoke(wordDoc, "SaveAs", Dispatch.Method, new Object[] {wordFile, new Variant(1)}, new int[1]);             Dispatch.call(wordDoc, "Close", new Variant(false));         } catch (Exception e) {             e.printStackTrace();         } finally {             app.invoke("Quit", new Variant[] {});         } }

来自: http://my.oschina.net/sunboy1116/blog/591493

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn