如何从java应用程序打印出ms word文件

发布于 2024-08-25 07:58:53 字数 52 浏览 5 评论 0原文

打印 ms word 文件(myfile.doc)以从 java 应用程序打印......

Print ms word file (myfile.doc) to get printed from java application....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

泪意 2024-09-01 07:58:53

此示例来自 OpenOffice API 可能有用。

This example from the OpenOffice API might be useful.

孤独陪着我 2024-09-01 07:58:53

Apache POI 系统 ( http://poi.apache.org/ ) 明确设计用于与 MS 交互文件。

The Apache POI system ( http://poi.apache.org/ ) is explicitly designed to interface with MS documents.

童话里做英雄 2024-09-01 07:58:53

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.

心在旅行 2024-09-01 07:58:53

这可能不是最有效的方法,但如果您有 MS Word,它就有效。您可以使用此命令让 Word 打印文件:

start /min winword <filename> /q /n /f /mFilePrint /mFileExit

替换为文件名。如果包含空格,则必须用双引号引起来。 (例如 file.rtf"A File.docx"

下面是一个 Java 方法和 C++ 函数,它将文件名作为参数并打印该文件:

Java

public void printWordFile(String filename){
  System.getRuntime().exec("start /min winword \"" + filename +
    "\" /q /n /f /mFilePrint /mFileExit");
}

C++

//Be sure to #include <string.h>    

void wordprint(char* filename){
  char* command = new char[64 + strlen(filename)];
  strcpy(command, "start /min winword \"");
  strcat(command, filename);
  strcat(command, "\" /q /n /f /mFilePrint /mFileExit");
  system(command);
  delete command;
}

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:

start /min winword <filename> /q /n /f /mFilePrint /mFileExit

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

public void printWordFile(String filename){
  System.getRuntime().exec("start /min winword \"" + filename +
    "\" /q /n /f /mFilePrint /mFileExit");
}

C++

//Be sure to #include <string.h>    

void wordprint(char* filename){
  char* command = new char[64 + strlen(filename)];
  strcpy(command, "start /min winword \"");
  strcat(command, filename);
  strcat(command, "\" /q /n /f /mFilePrint /mFileExit");
  system(command);
  delete command;
}

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 the start 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 print
dialog 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.

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