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

WBOY
Release: 2016-06-21 09:01:30
Original
1546 people have browsed it

摘要 这种方式的好处是生成的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[] {});         } }
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!