[prev in list] [next in list] [prev in thread] [next in thread]
List: poi-user
Subject: Re: Help reading formula in a spreadsheet..
From: <deshmol-lists () yahoo ! com>
Date: 2006-08-24 21:20:55
Message-ID: 20060824212055.23299.qmail () web32006 ! mail ! mud ! yahoo ! com
[Download RAW message or body]
1. If the xls is created by Excel and not by using
POI, you can simply read the "cached" evaluation of
the formula by using the appropriate
HSSFCell.get###CellValue() method. eg. if you expect
the cell to have a formula that evaluates to a number,
you can simply do:
HSSFCell cell = ... // get the reference to the cell
double value = cell.getNumericCellValue();
2. I noticed you had:
-- snip --
HSSFFormulaEvaluator.CellValue cellValue =
evaluator.evaluate(cell);
String a = String.valueOf(cellValue);
System.out.println("THE FORMULA CELL HAS : " + a);
-- snip --
If you must use the FormulaEvaluator, you will need to
inspect "type" of the CellValue returned by the
formula evaluation and use the appropriate getter as
so:
-- code --
HSSFFormulaEvaluator.CellValue cellValue =
evaluator.evaluate(cell);
switch (cellValue.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
// blah
case HSSFCell.CELL_TYPE_STRING:
// blah
// etc...
}
-- code --
Of course, if you are sure that the formula evaluates
to a number, you can simply do:
cellValue.getNumberValue() after the call to
evaluator.evaluate(cell).
HTH,
~ amol
---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic