Bug 44098

Summary: About Excel Formula can NOT calculate itself, but version 2.5 is OK
Product: POI Reporter: Xin Hu <huxin0124>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED INVALID    
Severity: critical CC: huxin0124
Priority: P1    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Xin Hu 2007-12-18 18:12:22 UTC
Dear all,
I use poi-bin-3.0.1-FINAL-20070705.
I found a strange thing that I load an xls file and export to another file 
without any operate, the new file formula can't calculate itself, but after i 
double click the formula cell, the value appeared.
my code:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelTest
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		try
		{
			FileInputStream fis = new FileInputStream(new File
("123.xls"));
			HSSFWorkbook wb = new HSSFWorkbook(fis);
			fis.close();
			
			HSSFSheet sheet = wb.getSheetAt(0);
			HSSFRow row0 = sheet.getRow(0);
			HSSFRow row1 = sheet.getRow(1);
			HSSFRow row2 = sheet.getRow(2);
			
			short col1 = 0;
			HSSFCell cell1 = row1.getCell(col1);
			cell1.setCellValue(14.1);
			HSSFCell cell2 = row2.getCell(col1);
			cell2.setCellValue(16.1);
			
			FileOutputStream fos = new FileOutputStream(new File
("1234.xls"));
			wb.write(fos);
			fos.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}
thank you all!
p.s. my excel version is 2003.
Comment 1 Nick Burch 2007-12-21 04:21:59 UTC
With POI 3.x, you can evaluate the formulas yourself, to have them re-calculate
to match changes in your spreadsheet

See http://poi.apache.org/hssf/eval.html