Here's the code: HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell( (short) 0); cell.setCellFormula("SUM(1,2)"); double num = cell.getNumericCellValue(); //0.0 will be printed out System.out.println(num); It returned 0.0, instead of 3.
POI does NOT automatically calculate formulas. POI is essentially a file format processor, not a functional replacement for excel. To evaluate formulas, you'll have to open the sheet in Excel. For simpler formulas, you can use the Formula Evaluator in poi's scratchpad. http://jakarta.apache.org/poi/hssf/eval.html