Example usage for org.apache.poi.ss.formula.eval EvaluationException getErrorEval

List of usage examples for org.apache.poi.ss.formula.eval EvaluationException getErrorEval

Introduction

In this page you can find the example usage for org.apache.poi.ss.formula.eval EvaluationException getErrorEval.

Prototype

public ErrorEval getErrorEval() 

Source Link

Usage

From source file:com.iesvirgendelcarmen.acceso.tema01.CalculateMortgage.java

License:Apache License

@Override
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {

    // verify that we have enough data
    if (args.length != 3) {
        return ErrorEval.VALUE_INVALID;
    }/*from ww  w.  j av a 2s  .  co m*/

    // declare doubles for values
    double principal, rate, years, result;
    try {
        // extract values as ValueEval
        ValueEval v1 = OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex());
        ValueEval v2 = OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex());
        ValueEval v3 = OperandResolver.getSingleValue(args[2], ec.getRowIndex(), ec.getColumnIndex());

        // get data as doubles
        principal = OperandResolver.coerceValueToDouble(v1);
        rate = OperandResolver.coerceValueToDouble(v2);
        years = OperandResolver.coerceValueToDouble(v3);

        result = calculateMortgagePayment(principal, rate, years);
        System.out.println("Result = " + result);

        checkValue(result);

    } catch (EvaluationException e) {
        return e.getErrorEval();
    }

    return new NumberEval(result);
}

From source file:com.wantdo.stat.excel.poi_src.formula.CalculateMortgage.java

License:Apache License

public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {

    // verify that we have enough data
    if (args.length != 3) {
        return ErrorEval.VALUE_INVALID;
    }/* w w w. j  a  va  2 s . c  om*/

    // declare doubles for values
    double principal, rate, years, result;
    try {
        // extract values as ValueEval
        ValueEval v1 = OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex());
        ValueEval v2 = OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex());
        ValueEval v3 = OperandResolver.getSingleValue(args[2], ec.getRowIndex(), ec.getColumnIndex());

        // get data as doubles
        principal = OperandResolver.coerceValueToDouble(v1);
        rate = OperandResolver.coerceValueToDouble(v2);
        years = OperandResolver.coerceValueToDouble(v3);

        result = calculateMortgagePayment(principal, rate, years);
        System.out.println("Result = " + result);

        checkValue(result);

    } catch (EvaluationException e) {
        return e.getErrorEval();
    }

    return new NumberEval(result);
}

From source file:de.enerko.reports2.functions.NormInv.java

License:Apache License

public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
    try {/* w  w  w .j ava2  s .  com*/
        final ValueEval p = OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex());
        final ValueEval mu = OperandResolver.getSingleValue(args[1], ec.getRowIndex(), ec.getColumnIndex());
        final ValueEval sigma = OperandResolver.getSingleValue(args[2], ec.getRowIndex(), ec.getColumnIndex());
        return new NumberEval(this.compute(OperandResolver.coerceValueToDouble(p),
                OperandResolver.coerceValueToDouble(mu), OperandResolver.coerceValueToDouble(sigma)));
    } catch (EvaluationException e) {
        return e.getErrorEval();
    }
}

From source file:nl.eur.ese.spreadsheettest.DStarRunner.java

License:Apache License

public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval database, ValueEval filterColumn,
        ValueEval conditionDatabase) {//from   ww w.  ja va2s  .c om
    // Input processing and error checks.
    if (!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) {
        return ErrorEval.VALUE_INVALID;
    }
    TwoDEval db = (TwoDEval) database;
    TwoDEval cdb = (TwoDEval) conditionDatabase;

    int fc;
    try {
        fc = getColumnForName(filterColumn, db);
    } catch (EvaluationException e) {
        return ErrorEval.VALUE_INVALID;
    }
    if (fc == -1) { // column not found
        return ErrorEval.VALUE_INVALID;
    }

    // Create an algorithm runner.
    IDStarAlgorithm algorithm = fac.create();

    // Iterate over all DB entries.
    for (int row = 1; row < db.getHeight(); ++row) {
        boolean matches = true;
        try {
            matches = fullfillsConditions(db, row, cdb);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }
        // Filter each entry.
        if (matches) {
            try {
                ValueEval currentValueEval = solveReference(db.getValue(row, fc));
                // Pass the match to the algorithm and conditionally abort the search.
                boolean shouldContinue = algorithm.processMatch(currentValueEval);
                if (!shouldContinue) {
                    break;
                }
            } catch (EvaluationException e) {
                return e.getErrorEval();
            }
        }
    }

    // Return the result of the algorithm.
    return algorithm.getResult();
}