Search in sources :

Example 36 with StringEval

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

the class TestTrunc method testTruncWithStringArg.

public void testTruncWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short) -1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 37 with StringEval

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

the class TestRoundFuncs method testRoundDownWithStringArg.

@Test
public void testRoundDownWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short) -1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 38 with StringEval

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

the class TestRoundFuncs method testRoundUpWithStringArg.

@Test
public void testRoundUpWithStringArg() {
    ValueEval strArg = new StringEval("abc");
    ValueEval[] args = { strArg, new NumberEval(2) };
    ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short) -1);
    assertEquals(ErrorEval.VALUE_INVALID, result);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 39 with StringEval

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

the class TestMatch method testSimpleWildcardValuesString.

public void testSimpleWildcardValuesString() {
    // Arrange
    ValueEval[] values = { new StringEval("Albert"), new StringEval("Charles"), new StringEval("Ed"), new StringEval("Greg"), new StringEval("Ian") };
    AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
    // Note String comparisons are case insensitive
    confirmInt(3, invokeMatch(new StringEval("e*"), ae, MATCH_EXACT));
    confirmInt(3, invokeMatch(new StringEval("*d"), ae, MATCH_EXACT));
    confirmInt(1, invokeMatch(new StringEval("Al*"), ae, MATCH_EXACT));
    confirmInt(2, invokeMatch(new StringEval("Char*"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("*eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("G?eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("??eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("G*?eg"), ae, MATCH_EXACT));
    confirmInt(4, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
    confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_EXACT));
    confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_LARGEST_LTE));
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) NumericValueEval(org.apache.poi.ss.formula.eval.NumericValueEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 40 with StringEval

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

the class Dec2Bin method evaluate.

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval placesVE) {
    ValueEval veText1;
    try {
        veText1 = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
    } catch (EvaluationException e) {
        return e.getErrorEval();
    }
    String strText1 = OperandResolver.coerceValueToString(veText1);
    Double number = OperandResolver.parseDouble(strText1);
    //If this number argument is non numeric, this function returns the #VALUE! error value.
    if (number == null) {
        return ErrorEval.VALUE_INVALID;
    }
    //If number < -512 or if number > 512, this function returns the #NUM! error value.
    if (number.longValue() < MIN_VALUE || number.longValue() > MAX_VALUE) {
        return ErrorEval.NUM_ERROR;
    }
    int placesNumber;
    if (number < 0 || placesVE == null) {
        placesNumber = DEFAULT_PLACES_VALUE;
    } else {
        ValueEval placesValueEval;
        try {
            placesValueEval = OperandResolver.getSingleValue(placesVE, srcRowIndex, srcColumnIndex);
        } catch (EvaluationException e) {
            return e.getErrorEval();
        }
        String placesStr = OperandResolver.coerceValueToString(placesValueEval);
        Double placesNumberDouble = OperandResolver.parseDouble(placesStr);
        //non numeric value
        if (placesNumberDouble == null) {
            return ErrorEval.VALUE_INVALID;
        }
        //If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.
        placesNumber = placesNumberDouble.intValue();
        if (placesNumber < 0 || placesNumber == 0) {
            return ErrorEval.NUM_ERROR;
        }
    }
    String binary = Integer.toBinaryString(number.intValue());
    if (binary.length() > DEFAULT_PLACES_VALUE) {
        binary = binary.substring(binary.length() - DEFAULT_PLACES_VALUE, binary.length());
    }
    //If DEC2BIN requires more than places characters, it returns the #NUM! error value.
    if (binary.length() > placesNumber) {
        return ErrorEval.NUM_ERROR;
    }
    return new StringEval(binary);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException)

Aggregations

StringEval (org.apache.poi.ss.formula.eval.StringEval)58 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)48 NumberEval (org.apache.poi.ss.formula.eval.NumberEval)29 Test (org.junit.Test)18 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)13 Calendar (java.util.Calendar)10 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)10 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)9 Date (java.util.Date)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)7 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)5 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)3 RefEval (org.apache.poi.ss.formula.eval.RefEval)3 BigDecimal (java.math.BigDecimal)1 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1