My original code seemed to replace the formula with the result of the formula.
I added a call to setCellFormula after the call to evalueInCell, and it keeps
both (the value and the formula):
if (formula != null)
{
evaluator.evaluateInCell (cell);
cell.setCellFormula (formula);
}
-----Original Message-----
From: J Keller [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2008 11:03 AM
To: POI Users List
Subject: RE: HSSF formula cells not calculating
Thanks. It's working now. I think my problem was that I wasn't calling the
Evaluator's setCurrentRow method:
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator (sheet, wb);
int rows = sheet.getLastRowNum();
for (int r = 0; r < rows; r++)
{
HSSFRow row = sheet.getRow (r);
evaluator.setCurrentRow (row);
short first = row.getFirstCellNum();
short last = row.getLastCellNum();
for (short c = first; c < last; c++)
{
HSSFCell cell = row.getCell (c);
if (cell != null &&
cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA)
{
String formula = cell.getCellFormula();
if (formula != null)
evaluator.evaluateInCell (cell);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]