protected ValueEval getItemInternal(int index) { int sIx = (index % _width) + _ref.getFirstSheetIndex(); return _ref.getInnerValueEval(sIx); } }
public ValueEval getItem(int index) { if(index >= _size) { throw new ArrayIndexOutOfBoundsException("Specified index (" + index + ") is outside the allowed range (0.." + (_size-1) + ")"); } int sheetIndex = _re.getFirstSheetIndex() + index; return _re.getInnerValueEval(sheetIndex); } public int getSize() {
protected ValueEval getItemInternal(int index) { int sIx = (index % _width) + _ref.getFirstSheetIndex(); return _ref.getInnerValueEval(sIx); } }
private ValueEval unwrapEval(ValueEval eval) { ValueEval comp = eval; while (comp instanceof RefEval) { RefEval ref = (RefEval) comp; comp = ref.getInnerValueEval(ref.getFirstSheetIndex()); } return comp; } /**
private static ValueEval chooseSingleElementFromRef(RefEval ref) { return ref.getInnerValueEval( ref.getFirstSheetIndex() ); }
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) { ValueEval arg = arg0; if (arg instanceof RefEval) { // always use the first sheet RefEval re = (RefEval)arg; arg = re.getInnerValueEval(re.getFirstSheetIndex()); } else if (arg instanceof AreaEval) { // when the arg is an area, choose the top left cell arg = ((AreaEval) arg).getRelativeValue(0, 0); } if (arg instanceof StringEval) { // Text values are returned unmodified return arg; } if (arg instanceof ErrorEval) { // Error values also returned unmodified return arg; } // for all other argument types the result is empty string return StringEval.EMPTY_INSTANCE; } }
/** * @return the number of evaluated cells in the range that match the specified criteria */ public static int countMatchingCellsInRef(RefEval refEval, I_MatchPredicate criteriaPredicate) { int result = 0; final int firstSheetIndex = refEval.getFirstSheetIndex(); final int lastSheetIndex = refEval.getLastSheetIndex(); for (int sIx = firstSheetIndex; sIx <= lastSheetIndex; sIx++) { ValueEval ve = refEval.getInnerValueEval(sIx); if(criteriaPredicate.matches(ve)) { result++; } } return result; } public static int countArg(ValueEval eval, I_MatchPredicate criteriaPredicate) {
eval = ((RefEval) eval).getInnerValueEval(((RefEval) eval).getFirstSheetIndex());
if (numberVE instanceof RefEval) { RefEval re = (RefEval) numberVE; number = OperandResolver.coerceValueToString(re.getInnerValueEval(re.getFirstSheetIndex())); } else { number = OperandResolver.coerceValueToString(numberVE);
private static ValueEval eval(double arg0, RefListEval aeRange, boolean descending_order) { int rank = 1; for(ValueEval ve : aeRange.getList()) { if (ve instanceof RefEval) { ve = ((RefEval) ve).getInnerValueEval(((RefEval) ve).getFirstSheetIndex()); } final Double value; if (ve instanceof NumberEval) { value = ((NumberEval)ve).getNumberValue(); } else { continue; } if(descending_order && value>arg0 || !descending_order && value<arg0){ rank++; } } return new NumberEval(rank); }
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) { final String hex; if (numberVE instanceof RefEval) { RefEval re = (RefEval) numberVE; hex = OperandResolver.coerceValueToString(re.getInnerValueEval(re.getFirstSheetIndex())); } else { hex = OperandResolver.coerceValueToString(numberVE); } try { return new NumberEval(BaseNumberUtils.convertToDecimal(hex, HEXADECIMAL_BASE, MAX_NUMBER_OF_PLACES)); } catch (IllegalArgumentException e) { return ErrorEval.NUM_ERROR; } }
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); }
private double getValue(ValueEval arg) throws EvaluationException { if (arg instanceof NumberEval) { return ((NumberEval) arg).getNumberValue(); } if(arg instanceof BlankEval) { return 0; } if (arg instanceof RefEval) { RefEval refEval = (RefEval)arg; if (refEval.getNumberOfSheets() > 1) { // Multi-Sheet references are not supported throw new EvaluationException(ErrorEval.VALUE_INVALID); } ValueEval innerValueEval = refEval.getInnerValueEval(refEval.getFirstSheetIndex()); if(innerValueEval instanceof NumberEval) { return ((NumberEval) innerValueEval).getNumberValue(); } if(innerValueEval instanceof BlankEval) { return 0; } } throw new EvaluationException(ErrorEval.VALUE_INVALID); } }
final int firstSheetIndex = re.getFirstSheetIndex(); final int lastSheetIndex = re.getLastSheetIndex(); for (int sIx = firstSheetIndex; sIx <= lastSheetIndex; sIx++) {
private static void collectValues(ValueEval arg, List<Double> temp) throws EvaluationException { if (arg instanceof TwoDEval) { TwoDEval ae = (TwoDEval) arg; int width = ae.getWidth(); int height = ae.getHeight(); for (int rrIx = 0; rrIx < height; rrIx++) { for (int rcIx = 0; rcIx < width; rcIx++) { ValueEval ve1 = ae.getValue(rrIx, rcIx); collectValue(ve1, temp, false); } } return; } if (arg instanceof RefEval) { RefEval re = (RefEval) arg; final int firstSheetIndex = re.getFirstSheetIndex(); final int lastSheetIndex = re.getLastSheetIndex(); for (int sIx = firstSheetIndex; sIx <= lastSheetIndex; sIx++) { collectValue(re.getInnerValueEval(sIx), temp, true); } return; } collectValue(arg, temp, true); }
RefEval re = (RefEval) eval; if (re.getNumberOfSheets() == 1) { return new SingleValueVector(re.getInnerValueEval(re.getFirstSheetIndex())); } else { return LookupUtils.createVector(re);
throw new EvaluationException(ErrorEval.VALUE_INVALID); eval = re.getInnerValueEval(re.getFirstSheetIndex()); } else { eval = arg;
/** * Note the formula result must either be a boolean result, or anything not in error. * If boolean, value must be true to pass, anything else valid is also passing, errors fail. * @see org.apache.poi.ss.formula.DataValidationEvaluator.ValidationEnum#isValidValue(Cell, DataValidationContext) */ public boolean isValidValue(Cell cell, DataValidationContext context) { // unwrapped single value ValueEval comp = context.getEvaluator().getWorkbookEvaluator().evaluate(context.getFormula1(), context.getTarget(), context.getRegion()); if (comp instanceof RefEval) { comp = ((RefEval) comp).getInnerValueEval(((RefEval) comp).getFirstSheetIndex()); } if (comp instanceof BlankEval) return true; if (comp instanceof ErrorEval) return false; if (comp instanceof BoolEval) { return ((BoolEval) comp).getBooleanValue(); } // empirically tested in Excel - 0=false, any other number = true/valid // see test file DataValidationEvaluations.xlsx if (comp instanceof NumberEval) { return ((NumberEval) comp).getNumberValue() != 0; } return false; // anything else is false, such as text } },
for (int sIx = re.getFirstSheetIndex(); sIx <= re.getLastSheetIndex(); sIx++) { collectValue(re.getInnerValueEval(sIx), true, temp);
protected ValueEval getItemInternal(int index) { int sIx = (index % _width) + _ref.getFirstSheetIndex(); return _ref.getInnerValueEval(sIx); } }