来自Jasper的excel报道

时间:2013-03-02 09:47:44

标签: java jasper-reports

在Excel中生成报告时,会显示以下错误消息。请帮忙!!!

代码: -

public String mainReportXLS(){

    Map<String, Object> jrxmlParams = null;

    try{

        String jrxmlFileName = "C:/Jasper/Dashboard2.jrxml";

        JasperReport objJReport = JasperCompileManager.compileReport(jrxmlFileName);
        connection = getConnection();

        JasperPrint print = JasperFillManager.fillReport(objJReport, jrxmlParams, connection);
        ByteArrayOutputStream outputByteArray = new ByteArrayOutputStream();
        //OutputStream outputfile= new FileOutputStream(new File("c:/output/JasperReport.xls"));

         JRXlsExporter exporterXLS = new JRXlsExporter();
         exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);
         exporterXLS.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/Jasper/Dashboard2.xls" );
         exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, outputByteArray);
         exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
         exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
         exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
         exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
         exporterXLS.exportReport();

         //outputfile.write(outputByteArray.toByteArray()); 


    }catch (Exception e) {
           System.out.print("Exceptiion" + e);
      }

    return null;
}

查看错误消息: -

]] Root cause of ServletException.
javax.faces.FacesException: Error calling action method of component with id headerForm:Report123456
    at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
    at javax.faces.component.UICommand.broadcast(UICommand.java:109)
    at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
    at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
    Truncated. see log file for complete stacktrace
Caused By: javax.faces.el.EvaluationException: Exception while invoking expression #{ReportsBB.extractJasper}
    at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:156)
    at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
    at javax.faces.component.UICommand.broadcast(UICommand.java:109)
    at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFWorkbook.getCreationHelper()Lorg/apache/poi/ss/usermodel/CreationHelper;
    at net.sf.jasperreports.engine.export.JRXlsExporter.openWorkbook(JRXlsExporter.java:282)
    at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:879)
    at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:629)
    at com.ultimatix.dealpricing.dao.ReportsDAO.mainReportXLS(ReportsDAO.java:137)
    at com.ultimatix.dealpricing.backingbeans.ReportsBackingBean.extractJasper(ReportsBackingBean.java:293)
    Truncated. see log file for complete stacktrace
> 

任何人都可以帮助.. !!!

1 个答案:

答案 0 :(得分:4)

请尝试以下代码,它对我有用

   File xlsx = new File("C:/Users/Sadagopan/Documents/sample.xlsX");
   JRXlsxExporter Xlsxexporter = new JRXlsxExporter();
   Xlsxexporter.setParameter(JRExporterParameter.JASPER_PRINT,
                             jasperPrint);
   Xlsxexporter.setParameter(JRExporterParameter.OUTPUT_FILE,
                             xlsx);
   Xlsxexporter.exportReport();

检查这个..“工具”&gt; “选项”&gt; “导出选项”标签&gt; “PDF”各种安全选项