java poi打印word_史上最强大Java 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 /q /n /f /mFilePrint /mFileExit

Replace  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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值