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.
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