Formulas and Evaluation

Harry · 24 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

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());

Formula cell evaluated with FormulaEvaluator

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.

Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in