I am writing a program to read some text or textfields from a Microsoft Office Word document and replace it with new words using Jacob. I got the help from this link http://tech-junki.blogspot.de/2009/06/java-jacob-edit-ms-word.html but it didn't work. Could you please help me by telling me how can I read some text and replace it with new text!? If you have a better idea, please tell me.
Note:
1- This method didn't give me any error but couldn't find the speciffic words!
2- How can I write an If() to know if our requested Search text (in this method arrayKeyString) exists or is written in ms word?
Thanks.
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);
}