【问题标题】:Print Excel from Java Directly to Print Server将 Excel 从 Java 直接打印到打印服务器
【发布时间】:2015-05-20 04:42:16
【问题描述】:

我们有一个 Java 应用程序,它可以从应用程序生成 Excel 文件。我正在寻找一种解决方案,可以帮助我将 excel 文件直接打印到基于 Linux 的打印服务器。

让我知道有哪些方法可以执行相同的操作。

【问题讨论】:

  • 您不能简单地将 Excel 文件发送到打印机。 Excel 本身打印为 PCL。另外应该从 Excel 文件中打印什么?工作簿中可能有多个工作表。所以最简单的方法是创建与 Excel 内容相同的 PDF 或 PS 并打印出来。

标签: java excel printing


【解决方案1】:

有一个叫做打印服务的java API,你可以按如下方式使用它

       PrintService defaultPrintService =  PrintServiceLookup.lookupDefaultPrintService();
       DocPrintJob printerJob = defaultPrintService.createPrintJob();
       File pdfFile = new File("yourfile");
       SimpleDoc simpleDoc = null;

       try {
           simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
       } catch (MalformedURLException ex) {
           ex.printStackTrace();
       }
       try {
           printerJob.print(simpleDoc, null);
       } catch (PrintException ex) {
           ex.printStackTrace();
       }

【讨论】:

  • 试一试,我从不将它用于 excel,但它适用于 pdf
  • 好的。现在也在尝试。
  • 试过了。它在 Paper 上打印有线字符。
猜你喜欢
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-10
  • 1970-01-01
  • 2014-10-11
  • 2014-06-23
  • 1970-01-01
相关资源
最近更新 更多