在JSF 2.x应用程序中,我使用PrimeFaces V-3.5和JasperReports V-5.2。我正在尝试使用JasperReports导出一些报告。我能够以PDF和RTF格式导出报告;但是,Excel格式不起作用,我遇到如下错误:
javax.el.ELException: java.lang.NoClassDefFoundError: jxl/read/biff/BiffException
这是我的报告生成器方法:
private void prepareReport(String reportPath, @SuppressWarnings("rawtypes") List beanList, String outputFormat, String reportName) {
JasperReport jReport = null;
JasperPrint jPrint = null;
try {
jReport = JasperCompileManager.compileReport(reportPath);
jPrint = JasperFillManager.fillReport(jReport, jasperParameter, new JRBeanCollectionDataSource(beanList));
} catch (JRException e) {
e.printStackTrace();
}
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
OutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (outputFormat.equals(OUTPUT_FORMAT_PDF)) {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".pdf");
JasperExportManager.exportReportToPdfStream(jPrint, outputStream);
} else if (outputFormat.equals(OUTPUT_FORMAT_EXCEL)) {
response.setContentType("application/xls");
response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".xls");
JExcelApiExporter exporter = new JExcelApiExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
} else if (outputFormat.equals(OUTPUT_FORMAT_RTF)) {
response.setContentType("application/rtf");
response.setHeader("Content-disposition", "attachment; filename=" + reportName + ".rtf");
JRRtfExporter exporter = new JRRtfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
}
} catch (JRException e) {
e.printStackTrace();
}
try {
outputStream.flush();
outputStream.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (IOException e) {
e.printStackTrace();
}
}
如何以Excel格式导出报告?