Привет. Я пытаюсь оценить значение ячейки с помощью вложенной формулы, используя apache POI 4.1.0.Когда я пытаюсь с нормальной формулой, она работает нормально.Примите во внимание приведенный ниже код:
FileInputStream inputExcelFile = new FileInputStream(new File(INPUT_FILE_NAME));
XSSFWorkbook workbook = new XSSFWorkbook(inputExcelFile);
XSSFSheet sheet = workbook.createSheet("Total");
Row row = sheet.createRow(0); Cell cell = row.createCell(0);
//setting formula in the cell
cell.setCellFormula("IF('Data Set'!B2=0,CONCATENATE(IF('Data Set'!J2="","UMS",'Data Set'!J2),"_",IF('Data Set'!K2<>"",'Data Set'!K2&"_",""),'Data Set'!H2),"");
Cell cellValue = formulaEvaluator.evaluateInCell(cell);
Теперь, если сделать cell.setCellFormula("CONCATENATE(F4,"/",G4)")
или любой прямой формальный код, этот код работает нормально, но при использовании вложенной формулы, такой как "IF (...., CONCATENATE (IF ...)) "выдает следующую ошибку
Exception in thread "main" org.apache.poi.ss.formula.eval.NotImplementedException: Error evaluating cell Total!A1
at org.apache.poi.ss.formula.WorkbookEvaluator.addExceptionInfo(WorkbookEvaluator.java:344)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:285)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluate(WorkbookEvaluator.java:216)
at org.apache.poi.xssf.usermodel.BaseXSSFFormulaEvaluator.evaluateFormulaCellValue(BaseXSSFFormulaEvaluator.java:56)
at org.apache.poi.ss.formula.BaseFormulaEvaluator.evaluateInCell(BaseFormulaEvaluator.java:145)
at org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.evaluateInCell(XSSFFormulaEvaluator.java:85)
at org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator.evaluateInCell(XSSFFormulaEvaluator.java:34)
at com.example.com.CollibraAutomationScript.evaluateFormula(CollibraAutomationScript.java:255)
at com.example.com.CollibraAutomationScript.main(CollibraAutomationScript.java:164)
Caused by: org.apache.poi.ss.formula.eval.NotImplementedException: Error evaluating cell 'Data Set'!B2
at org.apache.poi.ss.formula.WorkbookEvaluator.addExceptionInfo(WorkbookEvaluator.java:344)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:285)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateReference(WorkbookEvaluator.java:792)
at org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetRefEvaluator.java:48)
at org.apache.poi.ss.formula.SheetRangeEvaluator.getEvalForCell(SheetRangeEvaluator.java:74)
at org.apache.poi.ss.formula.LazyRefEval.getInnerValueEval(LazyRefEval.java:39)
at org.apache.poi.ss.formula.eval.OperandResolver.chooseSingleElementFromRef(OperandResolver.java:217)
at org.apache.poi.ss.formula.eval.OperandResolver.getSingleValue(OperandResolver.java:67)
at org.apache.poi.ss.formula.eval.RelationalOperationEval.evaluate(RelationalOperationEval.java:66)
at org.apache.poi.ss.formula.functions.Fixed2ArgFunction.evaluate(Fixed2ArgFunction.java:33)
at org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:153)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:541)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:275)
... 7 more
Caused by: org.apache.poi.ss.formula.eval.NotImplementedException: Error evaluating cell 'Data Set'!A2
at org.apache.poi.ss.formula.WorkbookEvaluator.addExceptionInfo(WorkbookEvaluator.java:344)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:285)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateReference(WorkbookEvaluator.java:792)
at org.apache.poi.ss.formula.SheetRefEvaluator.getEvalForCell(SheetRefEvaluator.java:48)
at org.apache.poi.ss.formula.SheetRangeEvaluator.getEvalForCell(SheetRangeEvaluator.java:74)
at org.apache.poi.ss.formula.LazyRefEval.getInnerValueEval(LazyRefEval.java:39)
at org.apache.poi.ss.formula.eval.OperandResolver.chooseSingleElementFromRef(OperandResolver.java:217)
at org.apache.poi.ss.formula.eval.OperandResolver.getSingleValue(OperandResolver.java:67)
at org.apache.poi.ss.formula.functions.Countif.evaluateCriteriaArg(Countif.java:498)
at org.apache.poi.ss.formula.functions.Countif.createCriteriaPredicate(Countif.java:470)
at org.apache.poi.ss.formula.functions.Countif.evaluate(Countif.java:442)
at org.apache.poi.ss.formula.functions.Fixed2ArgFunction.evaluate(Fixed2ArgFunction.java:33)
at org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:153)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:541)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:275)
... 18 more
Caused by: org.apache.poi.ss.formula.eval.NotImplementedFunctionException: _xlfn.CONCAT
at org.apache.poi.ss.formula.UserDefinedFunction.evaluate(UserDefinedFunction.java:56)
at org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:155)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateFormula(WorkbookEvaluator.java:541)
at org.apache.poi.ss.formula.WorkbookEvaluator.evaluateAny(WorkbookEvaluator.java:275)
... 31 more
Так apache poi не позволяет превышать вложенную формулу?потому что, когда я помещаю эту же формулу в таблицу Excel, она оценивается правильно.