public final class OperandResolver extends java.lang.Object
|Modifier and Type||Method and Description|
Implements (some perhaps not well known) Excel functionality to select a single cell from an area depending on the coordinates of the calling cell.
Applies some conversion rules if the supplied value is not already a number.
Applies some conversion rules if the supplied value is not already an integer.
Value is first coerced to a double ( See coerceValueToDouble() ).
Retrieves a single value from an area evaluation utilizing the 2D indices of the cell within its own area reference to index the value in the area evaluation.
Retrieves a single value from a variety of different argument types according to standard Excel rules.
Converts a string to a double using standard rules that Excel would use.
Tolerates leading and trailing spaces,
public static ValueEval getSingleValue(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException
arg- the evaluated argument as passed to the function or operator.
srcCellRow- used when arg is a single column AreaRef
srcCellCol- used when arg is a single row AreaRef
EvaluationException- if srcCellRow or srcCellCol do not properly index into an AreaEval. If the actual value retrieved is an ErrorEval, a corresponding EvaluationException is thrown.
public static ValueEval getElementFromArray(AreaEval ae, EvaluationCell cell)
ae- area reference after evaluation
cell- the source cell of the formula that contains its 2D indices
public static ValueEval chooseSingleElementFromArea(AreaEval ae, int srcCellRow, int srcCellCol) throws EvaluationException
The same concept is extended to references across sheets, such that even multi-row, multi-column areas can be useful.
Of course with carefully (or carelessly) chosen parameters, cyclic references can occur and
hence this method can throw a 'circular reference' EvaluationException. Note that
this method does not attempt to detect cycles. Every cell in the specified Area ae
has already been evaluated prior to this method call. Any cell (or cells) part of
ae that would incur a cyclic reference error if selected by this method, will
already have the value
null. Never ErrorEval.
EvaluationException- if there is a problem with indexing into the area, or if the evaluated cell has an error.
public static int coerceValueToInt(ValueEval ev) throws EvaluationException
Excel typically converts doubles to integers by truncating toward negative infinity.
The equivalent java code is:
return (int)d; // wrong - rounds toward zero
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException
ev- must be a
EvaluationException- if a StringEval is supplied and cannot be parsed as a double (See parseDouble() for allowable formats).
java.lang.RuntimeException- if the supplied parameter is not
public static java.lang.Double parseDouble(java.lang.String pText)
Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings.
" 123 " -> 123.0
".123" -> 0.123
"1E4" -> 1000
"-123" -> -123.0
These not supported yet:
" $ 1,000.00 " -> 1000.0
"$1.25E4" -> 12500.0
"5**2" -> 500
"250%" -> 2.5
nullif the specified text cannot be parsed as a number
public static java.lang.Double parseDateTime(java.lang.String pText)
public static java.lang.String coerceValueToString(ValueEval ve)
ve- must be a NumberEval, StringEval, BoolEval, or BlankEval
Copyright 2019 The Apache Software Foundation or its licensors, as applicable.