JasperReports 5.6: JRXlsExporter.setParameter is deprecated

前端 未结 3 829
無奈伤痛
無奈伤痛 2020-12-07 18:31

I have this code to export a JasperReprot to XLS:

        JasperPrint jprint=JasperFillManager.fillReport(expRpg, null, new JRBeanCollectionDataSource(datali         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 19:13

    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 classes PDF 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);
    
    exporter.exportReport();
    

    SimpleXlsReportConfiguration will have excel export related configuration. Set values as per your requirement

提交回复
热议问题