我有这段代码可以将 JasperReprot 导出到 XLS:
JasperPrint jprint=JasperFillManager.fillReport(expRpg, null, new JRBeanCollectionDataSource(datalist));
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jprint);
exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outStream);
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporter.exportReport();
升级到 JasperReports 5.6 所有 setParameter 都被标记为“已弃用”,我找不到修改此代码的文档。
如何使用 JasperReports 5.6 将报告导出到 xls?
最佳答案
JRExporter 在 5.6 中被弃用。他们引入了新的接口(interface) Exporter,并对所有导出器进行了改造,使其具有 ExporterInput、ReportExportConfiguration、ExporterConfiguration、ExporterOutput。见以下链接
http://jasperreports.sourceforge.net/api/net/sf/jasperreports/export/Exporter.html
这意味着您需要使用上述类或其子类创建配置,而不是 setParameter PDF 导出示例。 Excel 导出应遵循相同的方法
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(outputStream);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
Excel 对应
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(true);
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
SimpleXlsReportConfiguration 会有excel导出相关的配置。根据您的要求设置值
关于java - JasperReports 5.6 : JRXlsExporter. setParameter 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24117878/