use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Rate method evaluate.
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
if (args.length < 3) {
//First 3 parameters are mandatory
return ErrorEval.VALUE_INVALID;
}
double periods, payment, present_val, future_val = 0, type = 0, estimate = 0.1, rate;
try {
ValueEval v1 = OperandResolver.getSingleValue(args[0], srcRowIndex, srcColumnIndex);
ValueEval v2 = OperandResolver.getSingleValue(args[1], srcRowIndex, srcColumnIndex);
ValueEval v3 = OperandResolver.getSingleValue(args[2], srcRowIndex, srcColumnIndex);
ValueEval v4 = null;
if (args.length >= 4)
v4 = OperandResolver.getSingleValue(args[3], srcRowIndex, srcColumnIndex);
ValueEval v5 = null;
if (args.length >= 5)
v5 = OperandResolver.getSingleValue(args[4], srcRowIndex, srcColumnIndex);
ValueEval v6 = null;
if (args.length >= 6)
v6 = OperandResolver.getSingleValue(args[5], srcRowIndex, srcColumnIndex);
periods = OperandResolver.coerceValueToDouble(v1);
payment = OperandResolver.coerceValueToDouble(v2);
present_val = OperandResolver.coerceValueToDouble(v3);
if (args.length >= 4)
future_val = OperandResolver.coerceValueToDouble(v4);
if (args.length >= 5)
type = OperandResolver.coerceValueToDouble(v5);
if (args.length >= 6)
estimate = OperandResolver.coerceValueToDouble(v6);
rate = calculateRate(periods, payment, present_val, future_val, type, estimate);
checkValue(rate);
} catch (EvaluationException e) {
LOG.log(POILogger.ERROR, "Can't evaluate rate function", e);
return e.getErrorEval();
}
return new NumberEval(rate);
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Sumif method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2) {
AreaEval aeRange;
AreaEval aeSum;
try {
aeRange = convertRangeArg(arg0);
aeSum = createSumRange(arg2, aeRange);
} catch (EvaluationException e) {
return e.getErrorEval();
}
return eval(srcRowIndex, srcColumnIndex, arg1, aeRange, aeSum);
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Sumproduct method evaluate.
public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) {
int maxN = args.length;
if (maxN < 1) {
return ErrorEval.VALUE_INVALID;
}
ValueEval firstArg = args[0];
try {
if (firstArg instanceof NumericValueEval) {
return evaluateSingleProduct(args);
}
if (firstArg instanceof RefEval) {
return evaluateSingleProduct(args);
}
if (firstArg instanceof TwoDEval) {
TwoDEval ae = (TwoDEval) firstArg;
if (ae.isRow() && ae.isColumn()) {
return evaluateSingleProduct(args);
}
return evaluateAreaSumProduct(args);
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
throw new RuntimeException("Invalid arg type for SUMPRODUCT: (" + firstArg.getClass().getName() + ")");
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Indirect method evaluate.
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length < 1) {
return ErrorEval.VALUE_INVALID;
}
boolean isA1style;
String text;
try {
ValueEval ve = OperandResolver.getSingleValue(args[0], ec.getRowIndex(), ec.getColumnIndex());
text = OperandResolver.coerceValueToString(ve);
switch(args.length) {
case 1:
isA1style = true;
break;
case 2:
isA1style = evaluateBooleanArg(args[1], ec);
break;
default:
return ErrorEval.VALUE_INVALID;
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
return evaluateIndirect(ec, text, isA1style);
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Index method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
TwoDEval reference = convertFirstArg(arg0);
int columnIx = 0;
try {
int rowIx = resolveIndexArg(arg1, srcRowIndex, srcColumnIndex);
if (!reference.isColumn()) {
if (!reference.isRow()) {
// Note - the type of error changes if the pRowArg is negative
return ErrorEval.REF_INVALID;
}
// When the two-arg version of INDEX() has been invoked and the reference
// is a single column ref, the row arg seems to get used as the column index
columnIx = rowIx;
rowIx = 0;
}
return getValueFromArea(reference, rowIx, columnIx);
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
Aggregations