Formulas and Evaluation
Harry
· 24 Sep 2026
· 1 views
Log in to track your progress and mark lessons complete.
Sponsored
Writing Formulas
Cell total = row.createCell(2);
total.setCellFormula("B2*1.18"); // 18% tax, for example
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
CellValue v = eval.evaluate(total);
System.out.println("Computed: " + v.getNumberValue());Notes
- Formulas use English function names with commas (
SUM(A1:A10)) regardless of the Excel locale. - Call
evaluator.evaluateAll()before saving if downstream readers expect cached values. - POI supports most common functions (
SUM,IF,VLOOKUP, ...); exotic ones may return#NAME?until Excel recalculates.
Full runnable version: FormulaExample in the poi-examples repo.