如何从java应用程序打印出ms word文件
打印 ms word 文件(myfile.doc)以从 java 应用程序打印......
Print ms word file (myfile.doc) to get printed from java application....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此示例来自 OpenOffice API 可能有用。
This example from the OpenOffice API might be useful.
Apache POI 系统 ( http://poi.apache.org/ ) 明确设计用于与 MS 交互文件。
The Apache POI system ( http://poi.apache.org/ ) is explicitly designed to interface with MS documents.
Jacob 库可用于获取 Word 自动化容器的 COM 接口,并且您可以从那里打印(我们在我们的一个应用程序中经常这样做)。但是您必须在计算机上安装 Word 才能使其工作 - 如果您正在寻找无需安装 Word 即可工作的东西,您将不得不寻找其他地方。
The Jacob library can be used to obtain a COM interface to a Word automation container, and you can print from there (we do this quite a bit in one of our apps). But you have to have Word installed on the machine for this to work - if you are looking for something that can work without having Word installed, you'll have to look elsewhere.
这可能不是最有效的方法,但如果您有 MS Word,它就有效。您可以使用此命令让 Word 打印文件:
将
替换为文件名。如果包含空格,则必须用双引号引起来。 (例如file.rtf
、"A File.docx"
)下面是一个 Java 方法和 C++ 函数,它将文件名作为参数并打印该文件:
Java
C++
Explanation使用的开关
start /min
表示运行最小化后的程序。您必须执行此操作,否则打开文件后 Word 将保持打开状态。winword
告诉start
程序运行 Microsoft Word。/q
告诉 Word 不要显示启动屏幕。/n
表示打开一个新的 Word 实例,这样我们就不会干扰用户打开的其他文件。/f
表示打开文件的副本以防止修改。/mFilePrint
告诉 Word 显示其打印内容对话框,以便用户可以选择要使用的打印机以及份数等。
/mFileExit
表示在其他所有操作完成后立即关闭。除非将 Word 最小化,否则此操作不会起作用。This is probably not the most efficient method, but it works if you have MS Word. You can use this command to get Word print the file:
Replace
<filename>
with the filename. It must be enclosed in double-quotation marks if it contains spaces. (e.g.file.rtf
,"A File.docx"
)Here is a Java method and C++ function that takes the filename as an argument and prints the file:
Java
C++
Explanation of switches used
start /min
says to run the program that follows minimized. You must do this or Word will stay open after the file is opened.winword
tells thestart
program to run Microsoft Word./q
tells Word not to display the splash screen./n
says to open a new instance of Word so we don't interfere with other files the user has open./f
says to open a copy of the file to prevent modification./mFilePrint
tells Word to diplay its printdialog so the user can choose which printer they want to use and how many copies, etc.
/mFileExit
says to close as soon as everything else is done. This will not work unless Word is minimized.