2013-03-02 192 views
1

在excel中生成報告時,顯示以下錯誤消息。請幫忙!!!來自Jasper的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 
> 

任何一個可以請幫助.. !!!

回答

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(); 

檢查這個以及..安全

「工具」>「選項」>「導出選項」選項卡>「PDF」的各種選項
+1

再次感謝..還有一個疑問,我需要在PDF中生成報告後禁用PDF工具欄。已經從JRPDFExporter嘗試了一些參數......但無法實現。我的項目要求包括禁用PDF中的保存和打印選項。你可以好好建議。 在此先感謝! – Sainik 2013-03-06 05:38:48

+0

請投票上面的答案..你有沒有嘗試過這個選項:'jasperreports.export.pdf.encrypted'的pdf安全? – Sads 2013-03-06 06:55:28

+0

檢查此。以及「工具」>「選項」>「導出選項」選項卡>「PDF」安全的各種選項。 – Sads 2013-03-06 07:00:40