use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class IPMT method eval.
@Override
public double eval(ValueEval[] args, int srcCellRow, int srcCellCol) throws EvaluationException {
if (args.length != 4)
throw new EvaluationException(ErrorEval.VALUE_INVALID);
double result;
ValueEval v1 = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
ValueEval v2 = OperandResolver.getSingleValue(args[1], srcCellRow, srcCellCol);
ValueEval v3 = OperandResolver.getSingleValue(args[2], srcCellRow, srcCellCol);
ValueEval v4 = OperandResolver.getSingleValue(args[3], srcCellRow, srcCellCol);
double interestRate = OperandResolver.coerceValueToDouble(v1);
int period = OperandResolver.coerceValueToInt(v2);
int numberPayments = OperandResolver.coerceValueToInt(v3);
double PV = OperandResolver.coerceValueToDouble(v4);
result = Finance.ipmt(interestRate, period, numberPayments, PV);
checkValue(result);
return result;
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Index method resolveIndexArg.
/**
* @param arg a 1-based index.
* @return the resolved 1-based index. Zero if the arg was missing or blank
* @throws EvaluationException if the arg is an error value evaluates to a negative numeric value
*/
private static int resolveIndexArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval ev = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
if (ev == MissingArgEval.instance) {
return 0;
}
if (ev == BlankEval.instance) {
return 0;
}
int result = OperandResolver.coerceValueToInt(ev);
if (result < 0) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
return result;
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Value method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
ValueEval veText;
try {
veText = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
String strText = OperandResolver.coerceValueToString(veText);
Double result = convertTextToNumber(strText);
if (result == null) {
return ErrorEval.VALUE_INVALID;
}
return new NumberEval(result.doubleValue());
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Vlookup method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookup_value, ValueEval table_array, ValueEval col_index, ValueEval range_lookup) {
try {
// Evaluation order:
// lookup_value , table_array, range_lookup, find lookup value, col_index, fetch result
ValueEval lookupValue = OperandResolver.getSingleValue(lookup_value, srcRowIndex, srcColumnIndex);
TwoDEval tableArray = LookupUtils.resolveTableArrayArg(table_array);
boolean isRangeLookup = LookupUtils.resolveRangeLookupArg(range_lookup, srcRowIndex, srcColumnIndex);
int rowIndex = LookupUtils.lookupIndexOfValue(lookupValue, LookupUtils.createColumnVector(tableArray, 0), isRangeLookup);
int colIndex = LookupUtils.resolveRowOrColIndexArg(col_index, srcRowIndex, srcColumnIndex);
ValueVector resultCol = createResultColumnVector(tableArray, colIndex);
return resultCol.getItem(rowIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class WeekNum method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) {
double serialNum;
try {
serialNum = NumericFunction.singleOperandEvaluate(serialNumVE, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
Calendar serialNumCalendar = LocaleUtil.getLocaleCalendar();
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
int returnType;
try {
ValueEval ve = OperandResolver.getSingleValue(returnTypeVE, srcRowIndex, srcColumnIndex);
returnType = OperandResolver.coerceValueToInt(ve);
} catch (EvaluationException e) {
return ErrorEval.NUM_ERROR;
}
if (returnType != 1 && returnType != 2) {
return ErrorEval.NUM_ERROR;
}
return new NumberEval(this.getWeekNo(serialNumCalendar, returnType));
}
Aggregations