use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class XYNumericFunction method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
double result;
try {
ValueVector vvX = createValueVector(arg0);
ValueVector vvY = createValueVector(arg1);
int size = vvX.getSize();
if (size == 0 || vvY.getSize() != size) {
return ErrorEval.NA;
}
result = evaluateInternal(vvX, vvY, size);
} catch (EvaluationException e) {
return e.getErrorEval();
}
if (Double.isNaN(result) || Double.isInfinite(result)) {
return ErrorEval.NUM_ERROR;
}
return new NumberEval(result);
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Rept method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval text, ValueEval number_times) {
ValueEval veText1;
try {
veText1 = OperandResolver.getSingleValue(text, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
String strText1 = OperandResolver.coerceValueToString(veText1);
double numberOfTime = 0;
try {
numberOfTime = OperandResolver.coerceValueToDouble(number_times);
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
int numberOfTimeInt = (int) numberOfTime;
StringBuffer strb = new StringBuffer(strText1.length() * numberOfTimeInt);
for (int i = 0; i < numberOfTimeInt; i++) {
strb.append(strText1);
}
if (strb.toString().length() > 32767) {
return ErrorEval.VALUE_INVALID;
}
return new StringEval(strb.toString());
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Subtotal method evaluate.
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
// -1: first arg is used to select from a basic aggregate function
int nInnerArgs = args.length - 1;
if (nInnerArgs < 1) {
return ErrorEval.VALUE_INVALID;
}
final Function innerFunc;
try {
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRowIndex, srcColumnIndex);
int functionCode = OperandResolver.coerceValueToInt(ve);
innerFunc = findFunction(functionCode);
} catch (EvaluationException e) {
return e.getErrorEval();
}
// ignore the first arg, this is the function-type, we check for the length above
final List<ValueEval> list = new ArrayList<ValueEval>(Arrays.asList(args).subList(1, args.length));
Iterator<ValueEval> it = list.iterator();
// For array references it is handled in other evaluation steps, but we need to handle this here for references to subtotal-functions
while (it.hasNext()) {
ValueEval eval = it.next();
if (eval instanceof LazyRefEval) {
LazyRefEval lazyRefEval = (LazyRefEval) eval;
if (lazyRefEval.isSubTotal()) {
it.remove();
}
}
}
return innerFunc.evaluate(list.toArray(new ValueEval[list.size()]), srcRowIndex, srcColumnIndex);
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Roman method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval formVE) {
int number = 0;
try {
ValueEval ve = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
number = OperandResolver.coerceValueToInt(ve);
} catch (EvaluationException e) {
return ErrorEval.VALUE_INVALID;
}
if (number < 0) {
return ErrorEval.VALUE_INVALID;
}
if (number > 3999) {
return ErrorEval.VALUE_INVALID;
}
if (number == 0) {
return new StringEval("");
}
int form = 0;
try {
ValueEval ve = OperandResolver.getSingleValue(formVE, srcRowIndex, srcColumnIndex);
form = OperandResolver.coerceValueToInt(ve);
} catch (EvaluationException e) {
return ErrorEval.NUM_ERROR;
}
if (form > 4 || form < 0) {
return ErrorEval.VALUE_INVALID;
}
String result = this.integerToRoman(number);
if (form == 0) {
return new StringEval(result);
}
return new StringEval(makeConcise(result, form));
}
use of org.apache.poi.ss.formula.eval.EvaluationException in project poi by apache.
the class Sumproduct method getScalarValue.
private static double getScalarValue(ValueEval arg) throws EvaluationException {
ValueEval eval;
if (arg instanceof RefEval) {
RefEval re = (RefEval) arg;
if (re.getNumberOfSheets() > 1) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
eval = re.getInnerValueEval(re.getFirstSheetIndex());
} else {
eval = arg;
}
if (eval == null) {
throw new RuntimeException("parameter may not be null");
}
if (eval instanceof AreaEval) {
AreaEval ae = (AreaEval) eval;
// an area ref can work as a scalar value if it is 1x1
if (!ae.isColumn() || !ae.isRow()) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
eval = ae.getRelativeValue(0, 0);
}
return getProductTerm(eval, true);
}
Aggregations