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

WBOY
Freigeben: 2016-06-21 09:01:30
Original
1512 Leute haben es durchsucht

摘要 这种方式的好处是生成的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[] {});         } }
Nach dem Login kopieren

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

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!