| //要转换的word文件 String inFile = docpath; //txt文件 String tpFile = txtpath; boolean flag = false; try { //设置word不可见 app.setProperty("Visible", new Variant(false)); Object docs = app.getProperty("Documents").toDispatch(); //打开word文件 Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile, new Variant(false), new Variant(true)}, new int[1]).toDispatch(); //作为txt格式保存到临时文件 Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(10)}, new int[1]); 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("转化完毕!\n--------"); } } else { pathss = paths; //进入下一级目录 pathss = pathss + lists[i].getName() + "\\"; //递归遍历所有目录 change(path, pathss, savepaths); } } } public static String formatname(String name) { name = name.replace('、', '_'); name = name.replace(')', ')'); name = name.replace('(', '('); return name; } public static String pinyin(String path, String hanzi) { File f = new File(path); String pinyin = new String(""); pinyin = hanzi; |