我正在尝试解析包含各种公式的excel文件。我编写的代码能够解析几乎所有类型的公式,但是,某些单元格包含像= C20这样的另一个单元格的引用。在这种类型的单元格中,我的代码是
Unexpected arg eval type (org.apache.poi.ss.formula.eval.MissingArgEval)
我的代码能够处理以下类型
=IF(D14=0;" - ";E14/D14), =IF('TreeData-Report'!AB92="H";"";SUM('TreeData-Report'!C92:'TreeData-Report'!E92)) .. etc.
但是当它作为C20,D14 ..等单一论点出现时,它就失败了。 我会将代码发布到哪里失败
while (cellIterator.hasNext() && cellIteratorTotal.hasNext()) {
cellCount++;
Cell currentCell = cellIterator.next();
Cell currentCellTotal = cellIteratorTotal.next();
String cellValue = excelManager.evalCell(currentCell);// from here i am sending the value for validation
String cellValueTotal = excelManager.evalCell(currentCellTotal);
这是验证器类,我在其中查询单元格值的类型
public String evalCell(Cell cell) {
String cellValue = "";
if (cell.getCellTypeEnum() == CellType.STRING) {
cellValue = cell.getStringCellValue();
} else if (cell.getCellTypeEnum() == CellType.NUMERIC) {
cellValue = formatDoubleNumberToString(cell.getNumericCellValue());
} else if (cell.getCellTypeEnum() == CellType.FORMULA) {
cellValue = evalFormulaCell(cell);
}
return cellValue.trim();
}
public String evalFormulaCell(Cell cell) {
String cellValue = "";
switch (formulaEvaluator.evaluateFormulaCellEnum(cell)) {//Here the code fails if cell contains C20,D14.. etc this type of values
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case NUMERIC:
cellValue = formatDoubleNumberToString(cell.getNumericCellValue());
break;
case STRING:
cellValue = cell.getStringCellValue();
break;
case BLANK:
cellValue = "";
break;
case ERROR:
cellValue = "Error Occurred with Code :"+String.valueOf(cell.getErrorCellValue());
break;
case _NONE:
cellValue = "";
break;
// CELL_TYPE_FORMULA will never occur
case FORMULA:
cellValue = "";
break;
}
return cellValue;
}
请帮我处理这类错误,我很抱歉,我无法让我的帖子清晰透明。谢谢。我正在使用poi 3.16 jar。