Bug 41235

Summary: Wrong formula value on new cell!
Product: POI Reporter: Khanh Tran <trancongkhanh>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED INVALID    
Severity: critical    
Priority: P1    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Khanh Tran 2006-12-22 19:04:09 UTC
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.
Comment 1 Avik Sengupta 2007-01-16 02:05:15 UTC
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