如何设置 Jasper 使用 XSSF?

How to set Jasper to use XSSF?

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

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

这可能吗?我该怎么做?我需要使用 jasper,因为现在无法更改现有应用程序。

导出 jrxml 生成 ooxml XSSF, 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. In version 4 parameters where set instead of properties please see jasperreports-export-to-xlsx-not-xls