Search in sources :

Example 51 with StringEval

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

the class TestCountFuncs method testCaseInsensitiveStringComparison.

/**
     * String criteria in COUNTIF are case insensitive;
     * for example, the string "apples" and the string "APPLES" will match the same cells.
     */
public void testCaseInsensitiveStringComparison() {
    AreaEval range;
    ValueEval[] values;
    values = new ValueEval[] { new StringEval("no"), new StringEval("NO"), new StringEval("No"), new StringEval("Yes") };
    range = EvalFactory.createAreaEval("A1:A4", values);
    confirmCountIf(3, range, new StringEval("no"));
    confirmCountIf(3, range, new StringEval("NO"));
    confirmCountIf(3, range, new StringEval("No"));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) StringEval(org.apache.poi.ss.formula.eval.StringEval) AreaEval(org.apache.poi.ss.formula.eval.AreaEval)

Example 52 with StringEval

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

the class TestCountFuncs method testCountBlank.

public void testCountBlank() {
    AreaEval range;
    ValueEval[] values;
    values = new ValueEval[] { new NumberEval(0), // note - does match blank
    new StringEval(""), BoolEval.TRUE, BoolEval.FALSE, ErrorEval.DIV_ZERO, BlankEval.instance };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountBlank(2, range);
    values = new ValueEval[] { new NumberEval(0), // does match blank
    new StringEval(""), BlankEval.instance, BoolEval.FALSE, BoolEval.TRUE, BlankEval.instance };
    range = EvalFactory.createAreaEval("A1:B3", values);
    confirmCountBlank(3, range);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) 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 53 with StringEval

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

the class TestCountFuncs method testWildCards.

public void testWildCards() {
    I_MatchPredicate mp;
    mp = createCriteriaPredicate(new StringEval("a*b"));
    confirmPredicate(false, mp, "abc");
    confirmPredicate(true, mp, "ab");
    confirmPredicate(true, mp, "axxb");
    confirmPredicate(false, mp, "xab");
    mp = createCriteriaPredicate(new StringEval("a?b"));
    confirmPredicate(false, mp, "abc");
    confirmPredicate(false, mp, "ab");
    confirmPredicate(false, mp, "axxb");
    confirmPredicate(false, mp, "xab");
    confirmPredicate(true, mp, "axb");
    mp = createCriteriaPredicate(new StringEval("a~?"));
    confirmPredicate(false, mp, "a~a");
    confirmPredicate(false, mp, "a~?");
    confirmPredicate(true, mp, "a?");
    mp = createCriteriaPredicate(new StringEval("~*a"));
    confirmPredicate(false, mp, "~aa");
    confirmPredicate(false, mp, "~*a");
    confirmPredicate(true, mp, "*a");
    mp = createCriteriaPredicate(new StringEval("12?12"));
    confirmPredicate(false, mp, 12812);
    confirmPredicate(true, mp, "12812");
    confirmPredicate(false, mp, "128812");
}
Also used : I_MatchPredicate(org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate) StringEval(org.apache.poi.ss.formula.eval.StringEval)

Example 54 with StringEval

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

the class TestWorkdayFunction method testReturnWorkdaysSpanningAWeekendSubtractingDays.

@Test
public void testReturnWorkdaysSpanningAWeekendSubtractingDays() {
    Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 8, 27);
    Date expDate = expCal.getTime();
    ValueEval[] ve = { new StringEval("2013/09/30"), new NumberEval(-1) };
    double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
    assertEquals(41544.0, numberValue, 0);
    Date actDate = DateUtil.getJavaDate(numberValue);
    assertEquals(expDate, actDate);
}
Also used : Calendar(java.util.Calendar) StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval) Test(org.junit.Test)

Example 55 with StringEval

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

the class TestWorkdayFunction method testFailWhenArgumentsAreNotDatesNorNumbers.

@Test
public void testFailWhenArgumentsAreNotDatesNorNumbers() {
    ValueEval[] ve = { new StringEval("Potato"), new StringEval("Cucumber") };
    assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(ve, EC));
}
Also used : StringEval(org.apache.poi.ss.formula.eval.StringEval) ValueEval(org.apache.poi.ss.formula.eval.ValueEval) Test(org.junit.Test)

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