【问题标题】:How to set Jasper to use XSSF?如何设置 Jasper 使用 XSSF?
【发布时间】:2015-12-08 04:32:06
【问题描述】:

在现有系统中已经使用 jasper 5.0 并且据我所知它使用 poi HSSF 来生成 xls 数据,但是现在随着应用程序的成长,报告有一个大计数事务的问题产生。

我已经搜索了解决方案,并通过 XSSF 找到了 POI。因为 jasper 也使用 POI HSSF,所以我考虑在 JASPER 内部使用 XSSF。

这可能吗?我怎么能做到这一点?我需要使用 jasper,因为目前无法更改现有应用。

【问题讨论】:

    标签: jasper-reports apache-poi xssf hssf


    【解决方案1】:

    导出jrxml生成ooxmlXSSF,excel文件xlxs

    使用net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter

    例子:

    JasperPrint jasperPrint = JasperFillManager.fillReport(report, paramMap, connection); //Example of how to get the jasper print
    
    JRXlsxExporter exporter = new JRXlsxExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    File outputFile = new File("excelTest.xlsx");
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
    SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration(); 
    configuration.setOnePagePerSheet(false); //Set configuration as you like it!!
    configuration.setDetectCellType(true);
    configuration.setCollapseRowSpan(false);
    exporter.setConfiguration(configuration);
    exporter.exportReport();
    

    您的类路径中自然需要相关库(poi-ooxml.jar、poi-ooxml-schemas.jar、xmlbeans.jar),它们存在于 jasper 报告的分发中。

    JRXlsxExporter 从 4.5 版开始可用,这是jasper report 5.5.0 API。在版本 4 中设置参数而不是属性,请参阅 jasperreports-export-to-xlsx-not-xls

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多