Runtime.getRuntime.exec() 运行Word文档时出现问题

发布于 2024-08-27 10:07:07 字数 474 浏览 4 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恋竹姑娘 2024-09-03 10:07:08

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 you winword.execommand

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

幻想少年梦 2024-09-03 10:07:07

试试这个:

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

Try this:

String cmd = "c:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.exe /mOpenPage c:\\Navodilo.doc";
Process proc = Runtime.getRuntime().exec(cmd);
我不是你的备胎 2024-09-03 10:07:07

您应该尝试使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文