How to get cell value of formula (data) using apache poi

I am using Apache poi3.5 and java 1.6 for my application. here, I have one problem using the formula ...

my Cell has a formula (sheet2! C10), and the data inside this cell is of type String ... To access this cell, you also need to display the formula.

my Cell has a formula (sheet2! C11), and the data inside this cell is the type of number ... How to access this cell also needs to display the formula.

my Cell has a formula (sheet2! C10), and the data inside this cell is a date type ... How to access this cell and also display the formula.

+3
source share
2 answers
System.out.println("Formula Cell value :" + org.apache.poi.ss.usermodel.DataFormatter dataFormatter.formatCellValue(cell, formulaEvaluator));

it will return the value of the formula cell as a string ...

+5
source

, poi3.8.

Workbook xlsWorkbook = null;
Cell cell = null;

FormulaEvaluator formulaEval = xlsWorkbook.getCreationHelper().createFormulaEvaluator();
String value=formulaEval.evaluate(cell).formatAsString();
+7

Source: https://habr.com/ru/post/1774928/


All Articles