According to the docs, that is the method I want.  But it didn't work correctly 
for me.  When I used the "recalc spreadsheet" code from the docs page, it did 
put calculated values into the cells, but they would not update when I changed 
any of the data in the other cells referenced by the formula.

Once I added the call to setCellFormula, it worked fine.  This looks like a bug.

 for (Iterator rit = sheet.rowIterator(); rit.hasNext();)
 {
    HSSFRow row = (HSSFRow) rit.next();
    evaluator.setCurrentRow (row);
    for (Iterator cit = row.cellIterator(); cit.hasNext();)
    {
       HSSFCell cell = (HSSFCell) cit.next();
       if (cell != null && cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA)
       {
          String formula = cell.getCellFormula();
          if (formula != null)
          {
             evaluator.evaluateFormulaCell (cell);
             cell.setCellFormula (formula); // ADD THIS OR IT WON'T RECALC
          }
       }
    }
 }

-----Original Message-----
From: Nick Burch [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 19, 2008 6:33 AM
To: POI Users List
Subject: RE: HSSF formula cells not calculating

On Tue, 18 Mar 2008, J Keller wrote:
> 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):

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

You probably want evaluateFormulaCell, rather than evaluateInCell

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to