I modified your code just slightly to get it to compile and it seems
to run OK, producing your expected result (100.0).
The output is: Cell A4=100.0
Here is the modified code - please check it to make sure I didn't do
anything crazy
---------------
public static void main(String[] args) throws IOException {
HSSFWorkbook wbA = new HSSFWorkbook(new
FileInputStream("D:/Book1.xls"));
wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
HSSFFormulaEvaluator evalA = (HSSFFormulaEvaluator)
wbA.getCreationHelper().createFormulaEvaluator();
evalA.evaluateFormulaCell(wbA.getSheetAt(0).getRow(3).getCell(0));
printCell(wbA, evalA, 0, "A4");
}
private static void printCell(HSSFWorkbook wbA, HSSFFormulaEvaluator
evalA, int sheet, String str) {
CellReference cellReference = new CellReference(str);
Row row = wbA.getSheetAt(sheet).getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
evalA.clearAllCachedResultValues();
evalA.evaluate((HSSFCell) cell);
System.err.println("Cell " + str + "=" +
evalA.evaluate(cell).getNumberValue());
}
------------------
>From what I can tell, your sample code could be as simple as this:
HSSFWorkbook wbA = new HSSFWorkbook(new
FileInputStream("c:/josh/temp/Book1.xls"));
wbA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
HSSFFormulaEvaluator evalA = new HSSFFormulaEvaluator(wbA);
System.err.println("Cell A4=" +
evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0)).getNumberValue());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]