有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java获取Apache POI错误无法从文本公式单元格获取数值

我最近将代码降级为使用JDK1.4和Apache3.2(最终版本)

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

在降级之前,我的代码工作正常,没有遇到任何错误。我运行了与我以前的代码相同的示例,遇到了以下错误:

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

            }
        }

我认为这个错误是指单元格中的文本值。赛赛尔公式部分。。。但在Apache3.2中,我如何指定公式呢。有什么建议吗


共 (0) 个答案