我最近将我的代码降级为使用JDK 1.4和Apache 3.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)");
}
}
我认为这个错误是指cell.setCellFormula部分中的文本值...但是我如何在Apache 3.2中指定一个公式。有什么建议吗?