java把word格式文件转化成html显示

来源:互联网 发布:mac如何隐藏桌面文件夹 编辑:程序博客网 时间:2024/05/18 04:03
<pre name="code" class="html">public void wordToHtml(String xlsfile, String htmlfile) throws Exception {ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word应用程序try {File dir = new File(htmlfile+".files");File htm = new File(htmlfile+".htm");if(dir.exists()){dir.delete();}if(htm.exists()){htm.delete();}//设置word不可见app.setProperty("Visible", new Variant(false));//打开word文件Dispatch doc = app.getProperty("Documents").toDispatch();Dispatch doc1 = Dispatch.invoke(doc,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();//new Variant(i) i参数控制word文档另存为目标文档的格式:i=7时存为txt格式,//i=8时存为html格式Dispatch.invoke(doc1, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);Variant f = new Variant(false);Dispatch.call(doc1, "Close", f);} catch (Exception e) {e.printStackTrace();throw new Exception(e);} finally {app.invoke("Quit", new Variant[] {});}}


                                             
0 0
原创粉丝点击