简体   繁体   中英

Runtime.getRuntime.exec() problem with running Word document

when I write in commandline in windows:

C:\Program Files (x86)\Microsoft Office\Office12>winword.exe /mOpenPage c:\Navod
ilo.doc

It starts the word document with the macro /mOpenPage. I want to do the same thing from Java but its not going.

String[] cmd  = {"cmd","/c","c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe","/mOpenPage","c:\\Navodilo.doc"};
Process proc = Runtime.getRuntime().exec(cmd);

and how to open the document without to specify the path to winword.exe? but also to use /mOpenPage Macro

help?

Try this:

String cmd = "c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe /mOpenPage c:\\Navodilo.doc";
Process proc = Runtime.getRuntime().exec(cmd);

You should try using Desktop.open(File file) which will open the default application for your Word document. This is a better approach as you don't have to worry about where Office is installed.

Runtime.getRuntime.exec() does not open up a cmd window you have to invoke it with "cmd" as its argument and then use the inputstream to send you winword.exe command

http://forums.sun.com/thread.jspa?threadID=138974&tstart=140442

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM