Runtime.getRuntime.exec() 运行Word文档时出现问题
当我在 Windows 中的命令行中编写时:
C:\Program Files (x86)\Microsoft Office\Office12>winword.exe /mOpenPage c:\Navod
ilo.doc
它使用宏 /mOpenPage 启动 Word 文档。 我想用 Java 做同样的事情,但没有成功。
String[] cmd = {"cmd","/c","c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe","/mOpenPage","c:\\Navodilo.doc"};
Process proc = Runtime.getRuntime().exec(cmd);
以及如何在不指定winword.exe路径的情况下打开文档?还要使用/mOpenPage宏
帮忙?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Runtime.getRuntime.exec() 不会打开 cmd 窗口,您必须使用
"cmd"
作为参数来调用它,然后使用输入流向您发送winword.exe
命令http://forums.sun.com/thread.jspa? threadID=138974&tstart=140442
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 youwinword.exe
commandhttp://forums.sun.com/thread.jspa?threadID=138974&tstart=140442
试试这个:
Try this:
您应该尝试使用
Desktop.open(File file)
这将打开 Word 文档的默认应用程序。这是一种更好的方法,因为您不必担心 Office 的安装位置。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.