Hi,
I am using POI-3.5-FINAL-20090928.jar.
I changed my code as follows:
public static void main(String[] args) throws IOException {
HSSFWorkbook wbAA = new HSSFWorkbook(new
FileInputStream("D:/Book1.xls"));
wbAA.getSheetAt(0).getRow(1).getCell(0).setCellValue("Sheet2");
HSSFFormulaEvaluator evalAA = new HSSFFormulaEvaluator(wbAA);
CellValue cv =
evalAA.evaluate(wbAA.getSheetAt(0).getRow(3).getCell(0));
evalAA.clearAllCachedResultValues();
if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
System.err.println("Wrong result type - got " + cv.getCellType());
return;
}
System.err.println("Cell A4=" +cv.getNumberValue());
}
and I get:
Wrong result type - got 5
This means formula error. So INDIRECT is not evaluated corectly. Why?
I really need to make this working. What should I do?
Thanks,
Adrian
Josh Micich schreef:
You are probably still running a very old version of POI. In those
versions it was best practice to check the cell type of the
evaluation result (rather than just assume CELL_TYPE_NUMERIC). You
are probably getting CELL_TYPE_ERROR due to INDIRECT not being
implemented in your version of POI. Make a small change to your test
code to see:
----------------
public static void main(String[] args) throws IOException {
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);
CellValue cv = evalA.evaluate(wbA.getSheetAt(0).getRow(3).getCell(0));
if (cv.getCellType() != Cell.CELL_TYPE_NUMERIC) {
System.err.println("Wrong result type - got " +
cv.getCellType());
return;
}
System.err.println("Cell A4=" + cv.getNumberValue());
}
--------------
This change is not required if you are running anything newer than
version 3.5-beta4. Since then unimplemented functions cause
NotImplementedException to be thrown
---------------------------------------------------------------------
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]