首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

HTML转入word

2013-01-26 
HTML转为wordhtml内容转化为Word文档有两种方式实现:一.apache.poi代码如下:public static void htmlToWor

HTML转为word
html内容转化为Word文档

有两种方式实现:

一.apache.poi

代码如下:

public static void htmlToWord(String html, String docFile) {  ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word      try {  app.setProperty("Visible", new Variant(false));  Dispatch docs = app.getProperty("Documents").toDispatch();  Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, new Object[] { html, new Variant(false), new Variant(true) }, new int[1]).toDispatch();  Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] { docFile, new Variant(1) }, new int[1]);  Variant f = new Variant(false);  Dispatch.call(doc, "Close", f);  } catch (Exception e) {  e.printStackTrace();  } finally {  app.invoke("Quit", new Variant[] {});  ComThread.Release();  }  } public static void main(String[] args){ String fileName = "D:\\a.doc";     String content = "D:\\a.html";     htmlToWord(content,fileName);}


热点排行