JasperReports export to xlsx, not xls

后端 未结 4 2190
长发绾君心
长发绾君心 2020-12-14 11:44

I can\'t find how to export a file in .xlsx in JasperReports 4.1.1. The class:

JRXlsExporter

has not a Xlsx equivalent. And i can\'t

4条回答
  •  遥遥无期
    2020-12-14 12:31

    This answer is to help users with JASPER REPORT VERSION >5.6 (latest versions), hence remove the deprecated code.

    In later version >5.6 the JRXlsxExporter.setParameter(..) has been deprecated.

    You should use

    JRMapArrayDataSource dataSource = new JRMapArrayDataSource(data);
    
    JasperReport jasperReport = JasperCompileManager.compileReport(reportJRXMLSource);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
    
    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.setDetectCellType(true);//Set configuration as you like it!!
    configuration.setCollapseRowSpan(false);
    exporter.setConfiguration(configuration);
    exporter.exportReport();
    

提交回复
热议问题