// 建立ActiveX部件
wordCom = new ActiveXComponent("Word.Application");
//word应用程序不可见
wordCom.setProperty("Visible", False);
// 禁用宏
wordCom.setProperty("AutomationSecurity", new Variant(3));
try {
// 返回wrdCom.Documents的Dispatch
Dispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();//Documents表示word的所有文档窗口(word是多文档应用程序)
// 调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDoc
String password ="123";
wordDoc = Dispatch.call(wrdDocs, "Open", docFilePath, false,// ConfirmConversions
true, false, new Variant(password)).toDispatch();
Dispatch selection = Dispatch.get(wordCom, "Selection").toDispatch();
int pages = Integer.parseInt(Dispatch.call(selection,"information",4).toString());//总页数 //显示修订内容的最终状态
Dispatch.call(wordDoc, "AcceptAllRevisionsShown");
processId = processManager.findPid(PROCESS_COMMANDLINE);
return true;
} catch (ComFailException ex) {
ex.printStackTrace();
if (ex.getMessage().contains("密码不正确")) {//表示是加密文档
closeWord();//关闭文档
quit();//退出程序
throw new ComFailException("此文档已加密,解析失败");
}
} catch (IOException e) {
e.printStackTrace();
}
wordCom = new ActiveXComponent("Word.Application");
//word应用程序不可见
wordCom.setProperty("Visible", False);
// 禁用宏
wordCom.setProperty("AutomationSecurity", new Variant(3));
try {
// 返回wrdCom.Documents的Dispatch
Dispatch wrdDocs = wordCom.getProperty("Documents").toDispatch();//Documents表示word的所有文档窗口(word是多文档应用程序)
// 调用wrdCom.Documents.Open方法打开指定的word文档,返回wordDoc
String password ="123";
wordDoc = Dispatch.call(wrdDocs, "Open", docFilePath, false,// ConfirmConversions
true, false, new Variant(password)).toDispatch();
Dispatch selection = Dispatch.get(wordCom, "Selection").toDispatch();
int pages = Integer.parseInt(Dispatch.call(selection,"information",4).toString());//总页数 //显示修订内容的最终状态
Dispatch.call(wordDoc, "AcceptAllRevisionsShown");
processId = processManager.findPid(PROCESS_COMMANDLINE);
return true;
} catch (ComFailException ex) {
ex.printStackTrace();
if (ex.getMessage().contains("密码不正确")) {//表示是加密文档
closeWord();//关闭文档
quit();//退出程序
throw new ComFailException("此文档已加密,解析失败");
}
} catch (IOException e) {
e.printStackTrace();
}