0

我最近将我的代码降级为使用 JDK 1.4 和 Apache 3.2(Final)。

注意:对于那些问我为什么选择降级的人。我需要将它部署在使用这些设置的服务器上。

在降级所有内容之前,我的代码运行良好并且没有遇到错误。我运行了与以前的代码相同的示例并遇到了这个错误:

 java.lang.IllegalStateException: Cannot get a numeric value from a text formula cell
        at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch(HSSFCell.java:620)
        at org.apache.poi.hssf.usermodel.HSSFCell.checkFormulaCachedValueType(HSSFCell.java:625)
        at org.apache.poi.hssf.usermodel.HSSFCell.getNumericCellValue(HSSFCell.java:650)
        at org.apache.poi.hssf.usermodel.HSSFCell.setCellType(HSSFCell.java:308)
        at org.apache.poi.hssf.usermodel.HSSFCell.setCellType(HSSFCell.java:274)
at com.Generate.Excel.Actions.ProtonMonthlyStatActions.generatePRDXSheet(ProtonMonthlyStatActions.java:292)

错误指向由双星号包围的 else 部分中的这段代码:

 for (int x =0 ; x<dataList.getDHourList().size(); x++){ //for loop copying throughput data to excel file

            row = prdX.getRow(x+2);

            //checks if 3rd row in excel contains data (x+2) where x = 0 since excel is zero based
            if (isRowEmpty(prdX.getRow(x+2))== true){
                row = prdX.createRow(x+2); //creates row


                //for Hour Computation
                cell = row.createCell(colVal[2]);//creates column for Hour Computation using the formula specified
                cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
                cell.setCellFormula("MID("+formulaCell[0]+(x+3)+",12,2)");//fixed formula taken from Excel Template

            }   
            //If row is not empty each cells in every row is iterated and processed
            else {                      

                //for Hour Computation              
                cell = row.getCell(colVal[2], HSSFRow.CREATE_NULL_AS_BLANK);
                **cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);**
                cell.setCellFormula("MID("+formulaCell[0]+(x+3)+",12,2)");

            }
        }

我认为这个错误是指 cell.setCellFormula 部分中的文本值......但是我将如何在 Apache 3.2 中指定一个公式。对此有什么建议吗?

4

0 回答 0