A task I’m working on has grown. I need to open up some rtf documents using Office 2010, edit them, and then save them. Is there a way to automate this programatically using Java 6? I’m not aware of any java open source offerings that can run Office 2010 for something like this or what options there are for this type of task?
Share
You can use the java.lang.Runtime and java.lang.Process to execute external programs through a sort of command line approach. Check the exec method in Runtime which uses a String[], it’s the one that gives you program and argument options.
Process:
http://download.oracle.com/javase/6/docs/api/java/lang/Process.html
Runtime:
http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html
Here is a general idea of how it’s used
http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
Also here is a little bit about opening Word through a command line approach
http://support.microsoft.com/kb/210565
I’ve used this approach myself to open files in notepad and such
However, if you want to open these files and apply some automated edit to them, there may be a much different way of doing that, that may not require Word.