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 find a parameter to set the output format from xls to xlsx.
Navigate to http://[localhost]:8480/jasperserver-pro/. Log into Standalone as sysadmin. Right-click the report you wish to export, then click Export.
JasperReports Server Professional Edition is a commercially licensed reporting and analysis server based on JasperReports Server Community Edition. It is "visible" source - code comes with Professional Edition, but it is not free.
JasperReports Library is an open source reporting engine, written entirely in Java. JasperReports Library is able to use data coming from any kind of data source and produce documents that can viewed, printed, or exported in a variety of document formats, including HTML, PDF, Excel, OpenOffice and Word.
The JRXlsxExporter class should be used for exporting at XLSX format.
Till JasperReports 5.5.1 this code can be used for generating report at xlsx format:
JRMapArrayDataSource dataSource = new JRMapArrayDataSource(data);
JasperReport jasperReport = JasperCompileManager.compileReport(reportJRXMLSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRXlsExporterParameter.OUTPUT_FILE_NAME, outputFileName);
exporter.exportReport();
Since 5.5.2 version of library the JRAbstractExporter.setParameter(JRExporterParameter, Object) method is deprecated.
In this example I used JRS 6.4.1 version:
JasperReport jasperReport;
try (InputStream inputStream = JRLoader.getResourceInputStream(jrxmlFilePath)) {
jasperReport = JasperCompileManager.compileReport(JRXmlLoader.load(inputStream));
}
Map<String, Object> params = new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setOnePagePerSheet(true);
configuration.setIgnoreGraphics(false);
File outputFile = new File("output.xlsx");
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStream fileOutputStream = new FileOutputStream(outputFile)) {
Exporter exporter = new JRXlsxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(byteArrayOutputStream));
exporter.setConfiguration(configuration);
exporter.exportReport();
byteArrayOutputStream.writeTo(fileOutputStream);
}
Instead of using JRExporter.setParameter method we have to use implementation of XlsReportConfiguration interface. In example above I used SimpleXlsxReportConfiguration implementation of XlsReportConfiguration for defining settings specific to JRXlsxExporter exporter.
Advanced Excel Features
Batch Export Sample
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With