如何在java中打印word和excel文件?当我试图打印该单词或excel文件时,我将编码内容作为打印。 有没有可用的解决方案我可以使用java程序打印我的doc文件?
请找到以下代码
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();
}
答案 0 :(得分:1)
尝试:
Desktop desktop=Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.PRINT))
desktop.print(new File("yourFile.docx"));