如何用java打印word和excel文件?当我试图打印那个单词或excel文件时,我得到的是打印的编码内容。有没有可用的解决方案使用我可以使用java程序打印我的文档文件?
请在下面找到代码
XWPFDocument docx = new XWPFDocument(new FileInputStream(new File("D://TEST.docx")));
XWPFWordExtractor we = new XWPFWordExtractor(docx);
try {
new RemotePrintService().print(we.getText().getBytes(), "Default-Printer","");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
尝试:
Desktop desktop=Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.PRINT))
desktop.print(new File("yourFile.docx"));