| Object docs = app.getProperty("Documents").toDispatch(); Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch(); //打开word文件 Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]); //作为html格式保存到临时文件 Variant f = new Variant(false); Dispatch.call(doc, "Close", f); flag = true; } catch (Exception e) { e.printStackTrace(); } finally { app.invoke("Quit", new Variant[] {}); } System.out.println("转化完毕!"); } } else { pathss = paths; //进入下一级目录 pathss = pathss + lists[i].getName() + "\\"; //递归遍历所有目录 change(pathss, savepaths); } } } //------------------------------------------------------------------------------ //方法原型: main(String[] args) //功能描述: main文件 //输入参数: 无 //输出参数: 无 //返 回 值: 无 //其它说明: 无 //------------------------------------------------------------------------------ public static void main(String[] args) { String paths = new String("D:\\Work\\2004.10.8\\test system\\test01\\word\\"); String savepaths = new String ("D:\\Work\\2004.10.8\\test system\\test01\\html\\"); change(paths, savepaths); } } |
其中import的jar包是一个开源的东东,网上搜索即得。 Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]); 修改Variant(8)},里面得参数即可将Word转化为各种类型。
|