How do you export a JasperReport to an Excel file with multiple worksheets?

Jacob Schoen picture Jacob Schoen · Oct 20, 2010 · Viewed 26.8k times · Source

We have a report that the customer would like to have exported to an excel format where it has multiple worksheets. Essentially the two queries share the same parameters, but everything else is different.

In jasper-reports how do you export to an excel file with multiple worksheets (ideally from different data sources)?

Answer

andrei picture andrei · Apr 26, 2011

Thanks to this thread it really was easier for me to create an Excel export with multiple sheets. What I found out was that you could use the following:

ArrayList<JasperPrint> list = new  ArrayList<JasperPrint>();
list.add(jp1); list.add(jp2);
exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT_LIST, list);

and the exporter will automatically use every JasperPrint object to construct each sheet; also the name of the Jasper report (as specified in the jrxml file) is used as the name of each sheet.

Currently this solution works on my local project, so I just wanted to let you know.