http://momy.blogbus.com/logs/93567230.html
FileInputStream fis = new FileInputStream(filePath); //"C:/test.xls"
HSSFWorkbook wb = new HSSFWorkbook(fis);
for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
HSSFSheet sheet = wb.getSheetAt(sheetNum);
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
HSSFRow r = (HSSFRow)rit.next();
evaluator.setCurrentRow(r);
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
HSSFCell c = (HSSFCell)cit.next();
if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
//evaluator.evaluateFormulaCell(c);
cell.setCellFormula (formula); // ADD THIS OR IT WON'T RECALC
}
}
}
}
FileOutputStream fos = new FileOutputStream(filePath);
wb.write(fos);
fis.close();
fos.close();