Export Excel report from an Excel datasource JasperReport

897 Views Asked by At

I'm trying to automatically create report from an existing jasperreport template, I have already done this with CSV files, this is part of the code for CSV files :

Map parameters = new HashMap();
parameters.put("ReportTitle", "Address Report");
parameters.put("DataFile", name+".csv - CSV data source");
Set states = new HashSet();
states.add("Active");
states.add("Trial");
parameters.put("IncludedStates", states);

JasperPrint print = JasperFillManager.fillReport("../Desktop/Test/"+name+".jasper", parameters, getDataSource(name));

JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,  "../Desktop/Test/"+name+format.format(new Date())+".pdf");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
JasperExportManager.exportReportToPdfFile(print, "../Desktop/Test/"+name+format.format(new Date())+".pdf");

but I didn't find anything related to xlsx files or if there are any libraries that can help in this job, if anyone has any help or idea, I would appreciate it

Thank you

2

There are 2 best solutions below

0
Noblesse On BEST ANSWER

Actually I've found the answer, Methods like setParameters() and others have been deprecated in the newer versions of iReport. If you still want to use it you can download 4.5.0 libraries or lesser version This website has some good information on how to solve this problem : http://jasperreports.sourceforge.net/sample.reference/xlsxdatasource/index.html

I hope this may help

2
Akash Shah On

you can use JRXlsxExporter

Here Demo ,

JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);

exporter.exportReport();