poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Skye Shaw <ss...@lucas.cis.temple.edu>
Subject Re: HSSFCell With Formula Errors.
Date Wed, 15 Oct 2008 01:49:37 GMT
On Wed, 8 Oct 2008, Pierre Lavignotte wrote:
> I don't think that :
> HSSFFormulaEvaluator.CellValue v = fe.evaluate(cell)
> is ugly....
> It's the right way to evaluate a cell formula.

It's ugly because in order to get the cell's value I have to check 
HSSFCell's type, then, if it's a formula, I have to check 
HSSFFormulaEvaluator.CellValue's type against the same set of conditions 
(almost) I've just applied to HSSFCell:

String getStringFromCell(HSSFCell cell)
String val = cell.toString();
if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC) {
 	    short i = cell.getCellStyle().getDataFormat();
 	    String format = cellFormat.getFormat(i);
 	    if(HSSFDateUtil.isADateFormat((int)i,format)) {
 		//date stuff
else if(cell.getCellType()==HSSFCell.CELL_TYPE_FORMULA) {
   HSSFFormulaEvaluator.CellValue v = fe.evaluate(cell);
//Now recheck the type of HSSFFormulaEvaluator.CellValue
         return val;

Well, I shouldn't say have -as there are alternatives, (not 
evaluateInCell(HSSFCell cell) as that has problems; see earlier email)
though it seems to me that the public interface to HSSFCell is broken.

Maybe it's just my limited experience with POI, or maybe I'm just 
confused, though it appears that HSSFCell already knows the result of its 
formula upon construction, its already been evaluated. Yet I still have 
to use the formula evaluator to re "evaluate"- to tell me the state of the 
object, when the object (seems) to expose public methods for such 

Namely getCachedFormulaResultType().

Unfortunately this method raises an exception when called on a numeric 

Exception in thread "main" java.lang.IllegalStateException: Exception in 
thread "main" java.lang.IllegalStateException: Cannot get a text value 
from a numeric formula cell at 

Get a text value? I just wanted the integer result type, why do I care 
that about getting a text value from a numeric formula cell, I wanted an 
integer representing the CachedFormulaResultType.

I could go on, but I might be on the wrong track.


To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message