Hi Josh,

Thanks for the reply. I've tried using notifyUpdateCell after the cell update
but it's still giving me the same output.

The first section will update a cell on a worksheet, the the next section.

HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);

// update
sheet = wb.getSheet(sourceWorkSheetName); 
HSSFRow row = sheet.getRow(17);
HSSFCell cell = row.getCell( 2); 
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(Double.parseDouble(userAge));
evaluator.notifyUpdateCell(cell);

// Displaying output
sheet = wb.getSheet(targetWorkSheetName);
int rows  = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < rows; r++)
{
  row = sheet.getRow(r); 
  String   value = "";
  if (row != null)
  {
    int     cells = row.getPhysicalNumberOfCells();
    System.out.println("\r\nROW " + row.getRowNum());
    for (int c = 0; c < cells; c++)
    {
      cell  = row.getCell(c);
      if (cell != null)
      {
        switch (cell.getCellType())
        {
          case HSSFCell.CELL_TYPE_FORMULA :
            evaluator.evaluateFormulaCell(cell);
            HSSFFormulaEvaluator.CellValue cellValue = evaluator.evaluate(cell);
            Double numericCellValue = new Double(cellValue.getNumberValue());
            if (numericCellValue.isNaN())
            {
              value = value + cell.getRichStringCellValue().toString();
            }
            else
            {
              value = value + numericCellValue.toString();
            }
            break;
          case HSSFCell.CELL_TYPE_NUMERIC :
            value = value + cell.getNumericCellValue();
            break;
          case HSSFCell.CELL_TYPE_STRING :
            value = value + cell.getRichStringCellValue().getString();
            break;
        }
      }
    }
    System.out.println(value);
  }
}





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to