I don't think that :
HSSFFormulaEvaluator.CellValue v = fe.evaluate(cell)
is ugly....
It's the right way to evaluate a cell formula.
>From the CellValue, you can check the result type (which can be ERROR I
think), and read it accordingly.
I'm not used with the error cell so I can't tell you more on that.
Pierre
On Wed, Oct 8, 2008 at 1:14 AM, Skye Shaw <[EMAIL PROTECTED]>wrote:
> Hi,
>>
>> you should look at the HSSFFormulaEvaluator class.
>>
>> Pierre
>>
>
> Thanks Pierre. Unfortunately, the HSSFFormulaEvaluator causes problems too:
>
> public String getStringFromCell(HSSFCell cell)
> {
> String val = cell.toString();
> if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC) {
> //some stuff
> }
> else if(cell.getCellType()==HSSFCell.CELL_TYPE_FORMULA) {
> val = getStringFromCell(fe.evaluateInCell(cell));
> }
>
> return val;
> }
>
> Exception in thread "main" java.lang.RuntimeException: Error Value can only
> be 0
> ,7,15,23,29,36 or 42. It cannot be -60
> at
> org.apache.poi.hssf.record.BoolErrRecord.setValue(BoolErrRecord.java:124)
> at
> org.apache.poi.hssf.usermodel.HSSFCell.setCellErrorValue(HSSFCell.java:755)
> at
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.setCellValue(HSSFFormulaEvaluator.java:267)
> at
> org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluateInCell(HSSFFormulaEvaluator.java:239)
>
> HSSFFormulaEvaluator doesn't like circular references; I don't blame it.
>
> The alternate: HSSFFormulaEvaluator.CellValue v = fe.evaluate(cell).
> This is ugly, I think, as I have to (re)check the type of the CellValue
> before I can get the value.
>
> On a related note, when is a non-formula cell an error cell?
>
> -Skye
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Cordialement,
Pierre Lavignotte
Ingénieur Conception & Développement
http://pierre.lavignotte.googlepages.com