我正在编写一个程序,用于从Microsoft Office Word文档中读取一些文本或文本字段,并使用Jacob将其替换为新单词。 我从这个链接http://tech-junki.blogspot.de/2009/06/java-jacob-edit-ms-word.html得到了帮助,但它没有奏效。你能帮我告诉我如何阅读一些文本并用新文本代替它!? 如果你有更好的主意,请告诉我。阅读Ms Word中的单词并用新单词替换它(使用JAVA)
注:
1-这种方法并没有给我任何错误,但找不到speciffic话!
2-我如何编写一个If()来知道我们所请求的搜索文本(在此方法arrayKeyString中)是否存在或是用ms字写入?
谢谢。
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
//class
ActiveXComponent oWord = null;
Dispatch documents = null;
Dispatch document = null;
Dispatch selection = null;
//method
oWord = new ActiveXComponent("Word.Application");
documents = oWord.getProperty("Documents").toDispatch();
document = Dispatch.call(documents, "Open", finalName).toDispatch();
Dispatch selections = oWord.getProperty("Selection").toDispatch();
Dispatch findT = Dispatch.call(selections, "Find").toDispatch();
//hm is a Hashmap
for (int i=0; i<hm.size();i++){
hm.get(array[i].toString());
String arrayValString = (arrayVal[i].toString());
String arrayKeyString = array[i].toString();
// Here we should write an if() to check for our key word:
Dispatch.put(findT, "Text", arrayKeyString);
Dispatch.call(findT, "Execute");
Dispatch.put(selections, "Text", arrayValString);
}
你上面的进展如何?或者你有什么问题? –
它找不到这些单词并将其替换!它没有给我任何错误! –