Ok, I can duplicate the behavior with very simple code.

---------------

   public static void main (String[] args)
   {
      try
      {
         File ssFile = new File ("simple.xls");
         FileInputStream ssIn = new FileInputStream (ssFile);
         HSSFWorkbook wb = new HSSFWorkbook (ssIn);
         HSSFSheet sheet = wb.getSheetAt (0);
         HSSFRow row = sheet.getRow (3);
         HSSFCell cell = row.getCell ((short) 5);
         cell.setCellValue (25);

         // recalc
         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);
            }
         }

         FileOutputStream ssOut = new FileOutputStream ("changed.xls");
         wb.write (ssOut);
         ssOut.close();
      }
      catch (Exception x)
      {
         System.err.println (x);
      }
   }

---------------

However, I cannot duplicate the problem with a simple spreadsheet.

My spreadsheet is fairly complex (calculated cells that are used by other 
calculated cells, etc).  Unfortunately, I can't publish it (it's full of 
proprietary information).  I'll continue to try and isolate the problem.

-J

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

On Wed, 19 Mar 2008, J Keller wrote:
> 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.

Hmm, not sure if what you're seeing is a bug or not. Are you doing:
* update all cell values
* recalculate all formulas
* save
Or are you trying to do it in a different order? If you're doing it in
that order, and things aren't being correctly re-calculated, please do
open a new bug and upload a little unit test that shows off the issue.

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

That shouldn't be needed, assuming you're doing everything in the right
order

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