0

我正在尝试从Java生成 excel 报告。我在Java端使用Spring和iReport来开发 jasper 文件。尽管报告在iReport上运行良好,但我遇到了异常。我在iReport端用于报告的语言是JavaClassCast

整个错误控制台是:

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)

报告中是否存在数据类型不匹配或其他问题。由于iReport生成了 o/p,我不知道Java端出了什么问题。

我的实现:

    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`

这是我得到异常的地方。

4

1 回答 1

0

听起来像是在 JasperReports 主干修订版 6340 中修复的错误。

从 SVN 主干(或修补 5.0.1 源)构建一个 JasperReports jar 以检查它是否是同样的问题。

于 2013-10-17T08:04:31.940 回答