本文介绍了如何在Java中的Mac OS X上的Microsoft Word中打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS X上通过Java以编程方式打开* .docx文件.对于Windows和Linux,我已经可以通过以下方法使用它:

I am trying to open *.docx files programmatically from Java on Mac OS X. For Windows and Linux I already got it working with the following methods:

Windows:

Runtime.getRuntime().exec(new String[] {"C:\Program Files\Microsoft Office\Office15\WINWORD.EXE", "document.docx"});

Linux:

Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "/usr/bin/libreoffice", "document.docx"});

它如何与Mac OS X一起使用?我的Microsoft Office安装位于以下位置:

How does it work with Mac OS X ? My Microsoft Office installation is at the following location:

/Applications/Microsoft Office 2011/Microsoft Word.app

任何受到赞赏的想法-谢谢.

Any ideas highly appreciated - thanks.

推荐答案

有一个名为 open (/usr/bin/open),它接受应用程序的-a以及传递的文件,因此您可以执行以下操作:

There is a program called open (/usr/bin/open), which accepts -a for an application, and also files passed, so you can do something like:

Runtime.getRuntime().exec(new String[] {"open", "-a", "Microsoft Word", "document.docx"});

这篇关于如何在Java中的Mac OS X上的Microsoft Word中打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:21