Package org.apache.poi.hssf.record.formula.eval

Examples of org.apache.poi.hssf.record.formula.eval.EvaluationException


      for (int i = 0; i < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
          throw new EvaluationException(ErrorEval.NA);
        }
        return i-1;
      }
    }

    throw new EvaluationException(ErrorEval.NA);
  }
View Full Code Here


    int year = getYear(ds[0]);
    int month = (int) ds[1] - 1;
    int day = (int) ds[2];

    if (year < 0 || month < 0 || day < 0) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }

    if (year == 1900 && month == Calendar.FEBRUARY && day == 29) {
      return 60.0;
    }
View Full Code Here

    return result;
  }

  private static final void checkValue(double result) throws EvaluationException {
    if (Double.isNaN(result) || Double.isInfinite(result)) {
      throw new EvaluationException(ErrorEval.NUM_ERROR);
    }
  }
View Full Code Here

    protected OneArg() {
      // no fields to initialise
    }
    protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
      if (args.length != 1) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      double d = singleOperandEvaluate(args[0], srcCellRow, srcCellCol);
      return evaluate(d);
    }
View Full Code Here

    protected TwoArg() {
      // no fields to initialise
    }
    protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
      if (args.length != 2) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      double d0 = singleOperandEvaluate(args[0], srcCellRow, srcCellCol);
      double d1 = singleOperandEvaluate(args[1], srcCellRow, srcCellCol);
      return evaluate(d0, d1);
    }
View Full Code Here

      _maxArgs = maxArgs;
    }
    protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
      int nArgs = args.length;
      if (nArgs < _minArgs || nArgs > _maxArgs) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      double[] ds = new double[nArgs];
      for(int i=0; i<nArgs; i++) {
        ds[i] = singleOperandEvaluate(args[i], srcCellRow, srcCellCol);
      }
View Full Code Here

    } else {
      // ae is an area (not single row or column)
      if (!colArgWasPassed) {
        // always an error with 2-D area refs
        // Note - the type of error changes if the pRowArg is negative
        throw new EvaluationException(pRowIx < 0 ? ErrorEval.VALUE_INVALID : ErrorEval.REF_INVALID);
      }
      // Normal case - area ref is 2-D, and both index args were provided
      // if either arg is missing (or blank) the logic is similar to OperandResolver.getSingleValue()
      if (rowArgWasEmpty) {
        rowIx = srcRowIx - ae.getFirstRow();
      } else {
        rowIx = pRowIx-1;
      }
      if (colArgWasEmpty) {
        columnIx = srcColIx - ae.getFirstColumn();
      } else {
        columnIx = pColumnIx-1;
      }
    }

    int width = ae.getWidth();
    int height = ae.getHeight();
    // Slightly irregular logic for bounds checking errors
    if (!rowArgWasEmpty && rowIx >= height || !colArgWasEmpty && columnIx >= width) {
      // high bounds check fail gives #REF! if arg was explicitly passed
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    if (rowIx < 0 || columnIx < 0 || rowIx >= height || columnIx >= width) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return ae.getRelativeValue(rowIx, columnIx);
  }
View Full Code Here

    if (ev == BlankEval.INSTANCE) {
      return 0;
    }
    int result = OperandResolver.coerceValueToInt(ev);
    if (result < 0) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return result;
  }
View Full Code Here

    }
    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);
View Full Code Here

    int width = areaEval.getWidth();
    for (int rrIx=0; rrIx<height; rrIx++) {
      for (int rcIx=0; rcIx<width; rcIx++) {
        ValueEval ve = areaEval.getRelativeValue(rrIx, rcIx);
        if (ve instanceof ErrorEval) {
          throw new EvaluationException((ErrorEval) ve);
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.formula.eval.EvaluationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.