FileDocCategorySizeDatePackage
Len.javaAPI DocApache Poi 3.0.14740Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hssf.record.formula.functions

Len

public class Len extends TextFunction
author
Amol S. Deshmukh < amolweb at ya hoo dot com >

Fields Summary
Constructors Summary
Methods Summary
protected org.apache.poi.hssf.record.formula.eval.ValueEvalattemptXlateToText(org.apache.poi.hssf.record.formula.eval.ValueEval ve)
converts from Different ValueEval types to StringEval. Note: AreaEvals are not handled, if arg is an AreaEval, the returned value is ErrorEval.VALUE_INVALID

param
ve
return

        ValueEval retval;
        if (ve instanceof StringValueEval || ve instanceof RefEval) {
            retval = ve;
        }
        else if (ve instanceof BlankEval) {
            retval = ve;
        }
        else {
            retval = ErrorEval.VALUE_INVALID;
        }
        return retval;
    
public org.apache.poi.hssf.record.formula.eval.Evalevaluate(org.apache.poi.hssf.record.formula.eval.Eval[] operands, int srcCellRow, short srcCellCol)

        ValueEval retval = null;
        String s = null;
        
        switch (operands.length) {
        default:
            retval = ErrorEval.VALUE_INVALID;
            break;
        case 1:
            ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
            if (ve instanceof StringValueEval) {
                StringValueEval sve = (StringValueEval) ve;
                s = sve.getStringValue();
            }
            else if (ve instanceof RefEval) {
                RefEval re = (RefEval) ve;
                ValueEval ive = re.getInnerValueEval();
                if (ive instanceof BlankEval) {
                    s = re.isEvaluated() ? "0" : null;
                }
                else if (ive instanceof StringValueEval) {
                    s = ((StringValueEval) ive).getStringValue();
                }
                else if (ive instanceof BlankEval) {}
                else {
                    retval = ErrorEval.VALUE_INVALID;
                }
            }
            else if (ve instanceof BlankEval) {}
            else {
                retval = ErrorEval.VALUE_INVALID;
                break;
            }
        }
        
        if (retval == null) {
            s = (s == null) ? EMPTY_STRING : s;
            retval = new NumberEval(s.length());
        }
        
        return retval;
    
protected org.apache.poi.hssf.record.formula.eval.ValueEvalsingleOperandEvaluate(org.apache.poi.hssf.record.formula.eval.Eval eval, int srcRow, short srcCol)

        ValueEval retval;
        if (eval instanceof AreaEval) {
            AreaEval ae = (AreaEval) eval;
            if (ae.contains(srcRow, srcCol)) { // circular ref!
                retval = ErrorEval.CIRCULAR_REF_ERROR;
            }
            else if (ae.isRow()) {
                if (ae.containsColumn(srcCol)) {
                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
                    retval = attemptXlateToText(ve);
                }
                else {
                    retval = ErrorEval.VALUE_INVALID;
                }
            }
            else if (ae.isColumn()) {
                if (ae.containsRow(srcRow)) {
                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
                    retval = attemptXlateToText(ve);
                }
                else {
                    retval = ErrorEval.VALUE_INVALID;
                }
            }
            else {
                retval = ErrorEval.VALUE_INVALID;
            }
        }
        else {
            retval = attemptXlateToText((ValueEval) eval);
        }
        return retval;