问题描述
JasperPrint jprint = JasperFillManager.fillReport(expRpg,null,new JRBeanCollectionDataSource(数据列表));
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都被标记为已弃用,我无法找到适应此代码的文档。
如何将报告导出为xls与 JasperReports 5.6 ?
JRExporter在5.6中弃用。他们引入了新的界面导出器,并对所有出口商进行了改进,以具有ExporterInput,ReportExportConfiguration,ExporterConfiguration,ExporterOutput。见下面的链接
这意味着,而不是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对应
code> 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);
SimpleXlsReportConfiguration将具有excel导出相关配置。根据您的要求设置值
I have this code to export a JasperReprot to 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();
Upgrading to JasperReports 5.6 all setParameter are flagged as "deprecated" and I can not find documentation to adapt this code.
How to export a report to xls with JasperReports 5.6?
JRExporter became deprecated in 5.6. They introduced new interface Exporter and retrofitted all exporters to have ExporterInput, ReportExportConfiguration, ExporterConfiguration,ExporterOutput. See below link
http://jasperreports.sourceforge.net/api/net/sf/jasperreports/export/Exporter.html
This means that instead of setParameter, you need to create configuration using above mentioned classes or their child classesPDF export example. Excel export should follow same methodology
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(outputStream);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
Excel counterpart
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);
SimpleXlsReportConfiguration will have excel export related configuration. Set values as per your requirement
这篇关于JasperReports 5.6:不推荐使用JRXlsExporter.setParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!