在我使用jasperreports-3.7.4 jar以Excel格式下載Jasper Reports之前。現在我正在嘗試升級到jasperreports-6.3.1 jar。但它顯示錯誤,如「j ava.lang.NoSuchMethodError:org.apache.poi.hssf.usermodel.HSSFWorkbook.getCreationHelper()Lorg/apache/poi/hssf/usermodel/HSSFCreationHelper;」,同時調用exporterXLS.exportReport )方法。我也使用poi-3.6 jar。請提供解決方案來解決此問題。請找到我的代碼波紋管。java.lang.NoSuchMethodError:org.apache.poi.hssf.usermodel.HSSFWorkbook.getCreationHelper()Lorg/apache/poi/hssf/usermodel/HSSFCreationHelper;
handleDataBase db=null;
try {
OutputStream OutputStream = res.getOutputStream();
db = new handleDataBase();
Utility.comment("attra","before loading the Report "+new java.util.Date() + " - file name is "+reportFileName);
Connection connObj = db.getConnection();
//String jrPrint =JasperFillManager.fillReportToFile(jrxmlFile,params,connObj);
JasperPrint jasperPrint = JasperFillManager.fillReport(jrxmlFile, params, connObj);
Utility.comment("attra","After loading the Report "+new java.util.Date()+ " - file name is "+reportFileName);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT,jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,byteArrayOutputStream);
exporterXLS.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
//****************************Newly added by Shubham***************************************
exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_IMAGE_BORDER_FIX_ENABLED,Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED,Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS,Boolean.FALSE);
//***
exporterXLS.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
//*****************************************************************************************
exporterXLS.exportReport();//**Here I am getting above error**
//To enable report to get downloaded in IE on an https connection
res.setHeader("Cache-Control", "public");
res.setHeader("Pragma", "public");
res.setHeader("Content-Disposition","filename=\"" + reportFileName + "\";");
res.setContentType("application/vnd.ms-excel");
OutputStream.write(byteArrayOutputStream.toByteArray());
OutputStream.flush();
OutputStream.close();
} catch (Exception e) {
Utility.comment("attra","Exception inside generateReport "+e.getMessage());
} finally{
db.close();
}
您應該使用在JasperReports'* pom.xml *中定義的第三方庫的版本* –