Search in sources :

Example 96 with NumberEval

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

the class TestPmt method confirm.

private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) {
    ValueEval[] args = { new NumberEval(rate), new NumberEval(nper), new NumberEval(pv), new NumberEval(fv), new NumberEval(isBeginning ? 1 : 0) };
    confirm(expected, invokeNormal(args));
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 97 with NumberEval

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

the class TestTrunc method testTruncWithWholeNumber.

public void testTruncWithWholeNumber() {
    ValueEval[] args = { new NumberEval(200), new NumberEval(2) };
    @SuppressWarnings("static-access") ValueEval result = F.TRUNC.evaluate(args, -1, (short) -1);
    assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval) result).getNumberValue());
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 98 with NumberEval

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

the class TestXYNumericFunction method testBasic.

public void testBasic() {
    ValueEval[] xValues = { new NumberEval(1), new NumberEval(2) };
    ValueEval areaEvalX = createAreaEval(xValues);
    confirm(SUM_SQUARES, areaEvalX, areaEvalX, 10.0);
    confirm(DIFF_SQUARES, areaEvalX, areaEvalX, 0.0);
    confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalX, 0.0);
    ValueEval[] yValues = { new NumberEval(3), new NumberEval(4) };
    ValueEval areaEvalY = createAreaEval(yValues);
    confirm(SUM_SQUARES, areaEvalX, areaEvalY, 30.0);
    confirm(DIFF_SQUARES, areaEvalX, areaEvalY, -20.0);
    confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalY, 8.0);
}
Also used : ValueEval(org.apache.poi.ss.formula.eval.ValueEval) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 99 with NumberEval

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

the class EDate method evaluate.

public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
    if (args.length != 2) {
        return ErrorEval.VALUE_INVALID;
    }
    try {
        double startDateAsNumber = getValue(args[0]);
        int offsetInMonthAsNumber = (int) getValue(args[1]);
        Date startDate = DateUtil.getJavaDate(startDateAsNumber);
        Calendar calendar = LocaleUtil.getLocaleCalendar();
        calendar.setTime(startDate);
        calendar.add(Calendar.MONTH, offsetInMonthAsNumber);
        return new NumberEval(DateUtil.getExcelDate(calendar.getTime()));
    } catch (EvaluationException e) {
        return e.getErrorEval();
    }
}
Also used : Calendar(java.util.Calendar) EvaluationException(org.apache.poi.ss.formula.eval.EvaluationException) Date(java.util.Date) NumberEval(org.apache.poi.ss.formula.eval.NumberEval)

Example 100 with NumberEval

use of org.apache.poi.ss.formula.eval.NumberEval 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)

Aggregations

NumberEval (org.apache.poi.ss.formula.eval.NumberEval)123 ValueEval (org.apache.poi.ss.formula.eval.ValueEval)101 Test (org.junit.Test)34 StringEval (org.apache.poi.ss.formula.eval.StringEval)29 AreaEval (org.apache.poi.ss.formula.eval.AreaEval)21 EvaluationException (org.apache.poi.ss.formula.eval.EvaluationException)19 Calendar (java.util.Calendar)17 Date (java.util.Date)13 NumericValueEval (org.apache.poi.ss.formula.eval.NumericValueEval)12 ErrorEval (org.apache.poi.ss.formula.eval.ErrorEval)8 I_MatchPredicate (org.apache.poi.ss.formula.functions.CountUtils.I_MatchPredicate)5 RefEval (org.apache.poi.ss.formula.eval.RefEval)4 AssertionFailedError (junit.framework.AssertionFailedError)3 ValueVector (org.apache.poi.ss.formula.functions.LookupUtils.ValueVector)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 BoolEval (org.apache.poi.ss.formula.eval.BoolEval)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 SimpleDateFormat (java.text.SimpleDateFormat)1