JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "/myfile.xls");
ServletOutputStream pout = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline;filename=\"myfile.xls\"");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, pout);
exporter.exportReport();
When I loaded the JSP I got an error
JasperReports encountered this error :
java.lang.NoClassDefFoundError: org/apache/poi/hssf/util/HSSFColor$WHITE
The solution is to download poi-2.5.1.jar.
- Search Google for the file and you will find a download link in a few seconds
- Place the file in your webapps/$YOURAPPNAME/WEB-INF/lib directory and
- restart Tomcat
You should be good now.
Two notes:
- To test your files in iReports, you will need to go to iReports and the Tools>Options menu, then click the External Programs tab and for Excel, click the find button and navigate to Excel.exe on your hard drive.
- If you want your excel file to be clean looking, you will have to be careful with the sizing and placement of your fields, etc. The exporter will create a grid based on your elements EXACTLY. So if you leave little spaces between text fields those will be cells. I try to have all my text fields line up exactly side by side and with those above them and leave no white space in the bands.
No comments:
Post a Comment