2

My Spring Boot project using Apache Poi to read data from excel file.

i use FormulaEvaluator to calculate the value of cell

FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
formulaEvaluator.evaluateFormulaCell(cell)

I get the error

Could not resolve external workbook name 'excel_file_name.xlsx'. Workbook environment has not been set up.

How to resolve this issue ?

Tung Vo
  • 2,227
  • 5
  • 27
  • 45
  • Assuming you have that other referenced workbook, how about [FormulaEvaluator.setupReferencedWorkbooks](https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/FormulaEvaluator.html#setupReferencedWorkbooks-java.util.Map-) ? – Gagravarr Jan 11 '21 at 08:42
  • yes, just because this error happen when upload file so getCachedFormulaResultType maybe the good choice – Tung Vo Jan 12 '21 at 02:09

1 Answers1

1

I have fixed this issue by using method getCachedFormulaResultType as the document org.apache.poi.ss.usermodel.Cell

CellType getCachedFormulaResultType()

Only valid for formula cells

Returns: one of (CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, CellType.ERROR) depending on the cached value of the formula

i think method evaluateFormulaCell not work because the formular reference to another workbook

Tung Vo
  • 2,227
  • 5
  • 27
  • 45