I am trying to generate excel reports from Java . I am using Spring on Java side and iReport to develop the jasper files. I am getting ClassCast
exception although the report runs fine on iReport . The language I am using at iReport side for report is Java .
The whole error Console is:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
at net.sf.jasperreports.engine.JRAbstractExporter.getNumberCellValue(JRAbstractExporter.java:1198)
at net.sf.jasperreports.engine.JRAbstractExporter.getTextValue(JRAbstractExporter.java:1139)
at net.sf.jasperreports.engine.export.JRXlsExporter.createTextCell(JRXlsExporter.java:737)
at net.sf.jasperreports.engine.export.JRXlsExporter.exportText(JRXlsExporter.java:684)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:1195)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:940)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:629)
at com.ultimatix.dao.SubmissionReportJasperDaoImpl.mainReportXLS(SubmissionReportJasperDaoImpl.java:590)
at com.ultimatix.service.SubmissionReportJasperServiceImpl.excelDownload(SubmissionReportJasperServiceImpl.java:159)
Is there some mismatch of data types within the report or some other issue. Since iReport generates the o/p, I have no clue what is wrong at Java end.
My Implementation:
String mainDir="D:/Reports _ B_Type/";
String[] sheetNames={"Contract Details","Quick Selection","Basic Details","Billing Related Parameter","Discounts Applicable","Charges Applicable","Other Parameter","Slab-Wise Rates"};
Map<String, Object> parameters = new HashMap<String, Object>();
contractId = (String) contractData.get(DBConstants.PROC_PI_CONTRACT_ID);
versionNo = (String) contractData.get(DBConstants.VERSION_NO);
String sql=SQLQuery.getCommonHeaderDetailForFCmVersion();
ByteArrayOutputStream os1 = new ByteArrayOutputStream();
try
{
jdbcTemplate = new JdbcTemplate(dataSource);
contractDataList = jdbcTemplate.queryForList(sql,new Object[] {contractId,versionNo});
for (Map<String,Object> row : contractDataList) {
contractingCompany=(String) row.get(DBConstants.FCM_CONTRACT_INFO_CONTRACTING_COMPANY);
customerName=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CUSTOMER_NAME);
startDate=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CONTRACT_START_DATE);
endDate=(String) row.get(DBConstants.FCM_CONTRACT_INFO_MV_CONTRACT_END_DATE);
if(null != row.get(DBConstants.FCM_CONTRACT_INFO_MV_TOTAL_CONTRACT_VALUE))
{
tcsContractValue= row.get(DBConstants.FCM_CONTRACT_INFO_MV_TOTAL_CONTRACT_VALUE).toString();
}
contractStatus="E";
}
/*parameters to be passed in report */
parameters.put("ContractId", contractId);
parameters.put("VersionNo", versionNo);
parameters.put("SUBREPORT_DIR",mainDir);
parameters.put("ContractingCompany",contractingCompany);
parameters.put("CustomerName",customerName);
parameters.put("StartDate",startDate);
parameters.put("EndDate",endDate);
parameters.put("TcsContractValue",tcsContractValue);
parameters.put("ContractStatus",contractStatus);
connection = DataSourceUtils.getConnection(dataSource);
String reportTemplatePath = null;//path to find the template report
String fileSep = File.pathSeparator;
if(fileSep.equals(":") ){
}else{
reportTemplatePath =mainDir + "Main Report.jasper";
}
JasperPrint jasperPrint;
jasperPrint = JasperFillManager.fillReport(
reportTemplatePath,parameters,connection);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(
JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.SHEET_NAMES,sheetNames);
exporterXLS.setParameter(
JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(
JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
exporterXLS.setParameter(
JRXlsExporterParameter.CREATE_CUSTOM_PALETTE,Boolean.TRUE);//to generate closest matching color when report generated from java end.
try{
exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, os1);
**exporterXLS.exportReport();**
}
catch(Exception e)
{
e.getMessage();
e.printStackTrace();
}`enter code here`
This is where i get the exception.
Sounds like a bug that's been fixed at JasperReports trunk revision 6340.
Build a JasperReports jar from the SVN trunk (or patch the 5.0.1 sources) to check if it's the same problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.