public static boolean freeMakerWordToWord(String source,String target){
WordTOPdf pdf = new WordTOPdf();
System.out.println("FreemakerWord转Word开始启动...");
long start = System.currentTimeMillis();
ActiveXComponent app = null;
Dispatch doc = null;
try {
app = new ActiveXComponent("Word.Application");
app.setProperty("Visible", false);
Dispatch documents = app.getProperty("Documents").toDispatch();
// 打开FreeMarker生成的Word文档
doc = Dispatch.call(documents, "Open", source, false, true).toDispatch();
File tofile = new File(target);
if (tofile.exists()) {
tofile.delete();
}
// 另存为新的Word文档
Dispatch.call(doc, "SaveAs", target, 12);
Dispatch.call(doc, "Close", false);
System.out.println("FreemakerWord转Word结束...");
return true;
} catch (Exception e) {
System.out.println("FreemakerWord转Word出错:" + e.getMessage());
return false;
} finally {
if (app != null) {
app.invoke("Quit", new Variant[]{});
// app.invoke("Quit", wdDoNotSaveChanges);
}
ComThread.Release();
//关闭winword.exe进程
String command = "taskkill /f /im WINWORD.EXE";
try {
Runtime.getRuntime().exec(command);
} catch (Exception e) {
e.printStackTrace();
}
}
}