Search in sources :

Example 6 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.

the class TestSumproduct method testScalarSimple.

public void testScalarSimple() {
    RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
    ValueEval[] args = { refEval, new NumberEval(2) };
    ValueEval result = invokeSumproduct(args);
    confirmDouble(6D, result);
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 7 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.

the class TestMid method testUnusualArgs.

/**
	 * Valid cases where args are not precisely (string, int, int) but can be resolved OK.
	 */
public void testUnusualArgs() {
    // startPos with fractional digits
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
    // string startPos
    confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
    // text (first) arg type is number, other args are strings with fractional digits
    confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
    // startPos is 1x1 area ref, numChars is cell ref
    AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2) });
    RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
    confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
    confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
    confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
    confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 8 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.

the class EvaluationConditionalFormatRule method unwrapEval.

private ValueEval unwrapEval(ValueEval eval) {
    ValueEval comp = eval;
    while (comp instanceof RefEval) {
        RefEval ref = (RefEval) comp;
        comp = ref.getInnerValueEval(ref.getFirstSheetIndex());
    }
    return comp;
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval)

Example 9 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.

the class EDate method getValue.

private double getValue(ValueEval arg) throws EvaluationException {
    if (arg instanceof NumberEval) {
        return ((NumberEval) arg).getNumberValue();
    }
    if (arg instanceof BlankEval) {
        return 0;
    }
    if (arg instanceof RefEval) {
        RefEval refEval = (RefEval) arg;
        if (refEval.getNumberOfSheets() > 1) {
            // Multi-Sheet references are not supported
            throw new EvaluationException(ErrorEval.VALUE_INVALID);
        }
        ValueEval innerValueEval = refEval.getInnerValueEval(refEval.getFirstSheetIndex());
        if (innerValueEval instanceof NumberEval) {
            return ((NumberEval) innerValueEval).getNumberValue();
        }
        if (innerValueEval instanceof BlankEval) {
            return 0;
        }
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) BlankEval(org.apache.poi.ss.formula.eval.BlankEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 10 with RefEval

use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.

the class Bin2Dec method evaluate.

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) {
    final String number;
    if (numberVE instanceof RefEval) {
        RefEval re = (RefEval) numberVE;
        number = OperandResolver.coerceValueToString(re.getInnerValueEval(re.getFirstSheetIndex()));
    } else {
        number = OperandResolver.coerceValueToString(numberVE);
    }
    if (number.length() > 10) {
        return ErrorEval.NUM_ERROR;
    }
    String unsigned;
    //If the leftmost bit is 0 -- number is positive.
    boolean isPositive;
    if (number.length() < 10) {
        unsigned = number;
        isPositive = true;
    } else {
        unsigned = number.substring(1);
        isPositive = number.startsWith("0");
    }
    String value;
    try {
        if (isPositive) {
            //bit9*2^8 + bit8*2^7 + bit7*2^6 + bit6*2^5 + bit5*2^4+ bit3*2^2+ bit2*2^1+ bit1*2^0
            int sum = getDecimalValue(unsigned);
            value = String.valueOf(sum);
        } else {
            //The leftmost bit is 1 -- this is negative number
            //Inverse bits [1-9]
            String inverted = toggleBits(unsigned);
            // Calculate decimal number
            int sum = getDecimalValue(inverted);
            //Add 1 to obtained number
            sum++;
            value = "-" + sum;
        }
    } catch (NumberFormatException e) {
        return ErrorEval.NUM_ERROR;
    }
    return new NumberEval(Long.parseLong(value));
}
Also used : RefEval(org.apache.poi.ss.formula.eval.RefEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Aggregations

RefEval (org.apache.poi.ss.formula.eval.RefEval)12 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)9 TwoDEval (org.apache.poi.ss.formula.TwoDEval)5 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)5 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)5 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)4 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)3 StringEval (org.apache.poi.ss.formula.eval.StringEval)3 ThreeDEval (org.apache.poi.ss.formula.ThreeDEval)1 BlankEval (org.apache.poi.ss.formula.eval.BlankEval)1 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)1 StringValueEval (org.apache.poi.ss.formula.eval.StringValueEval)1 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)1