0

JSF 2.x应用程序中,我使用PrimeFaces V-3.5JasperReports V-5.2。我正在尝试使用JasperReports导出一些报告。我能够以PDFRTF格式导出报告;但是,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格式导出报告?

4

1 回答 1

0

您正在使用JExcelApiExporter。它正在使用JExcelApi库。

您可以检查JasperReportspom.xml文件中的依赖关系。JasperReports 5.2正在使用这个工件:

<dependency>
    <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6.10</version>
</dependency>

这意味着您应该将jxl-2.6.10.jar添加到您的应用程序类路径中(如果使用JasperReports 5.2)。

于 2013-10-25T17:26:17.540 回答