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

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


      _maxArgs = maxArgs;
    }
    protected final double eval(Eval[] 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

      NumberEval ne = (NumberEval) ve;
      temp.add(ne.getNumberValue());
      return;
    }
    if (ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) ve);
    }
    if (ve instanceof StringEval) {
      if (isViaReference) {
        // ignore all ref strings
        return;
      }
      String s = ((StringEval) ve).getStringValue();
      Double d = OperandResolver.parseDouble(s);
      if(d == null) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      temp.add(d.doubleValue());
      return;
    }
    if (ve instanceof BoolEval) {
View Full Code Here

      return new SingleValueVector(re.getInnerValueEval());
    }
    if (eval instanceof AreaEval) {
      ValueVector result = LookupUtils.createVector((AreaEval)eval);
      if (result == null) {
        throw new EvaluationException(ErrorEval.NA);
      }
      return result;
    }

    // Error handling for lookup_range arg is also unusual
    if(eval instanceof NumericValueEval) {
      throw new EvaluationException(ErrorEval.NA);
    }
    if (eval instanceof StringEval) {
      StringEval se = (StringEval) eval;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        // plain string
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // else looks like a number
      throw new EvaluationException(ErrorEval.NA);
    }
    throw new RuntimeException("Unexpected eval type (" + eval.getClass().getName() + ")");
  }
View Full Code Here

  private static double evaluateMatchTypeArg(Eval arg, int srcCellRow, short srcCellCol)
      throws EvaluationException {
    Eval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);

    if(match_type instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval)match_type);
    }
    if(match_type instanceof NumericValueEval) {
      NumericValueEval ne = (NumericValueEval) match_type;
      return ne.getNumberValue();
    }
    if (match_type instanceof StringEval) {
      StringEval se = (StringEval) match_type;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        // plain string
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // if the string parses as a number, it is OK
      return d.doubleValue();
    }
    throw new RuntimeException("Unexpected match_type type (" + match_type.getClass().getName() + ")");
View Full Code Here

      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

   * evaluates to an error.
   */
  private static double evaluate(int hours, int minutes, int seconds) throws EvaluationException {

    if (hours > 32767 || minutes > 32767 || seconds > 32767) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    int totalSeconds = hours * SECONDS_PER_HOUR + minutes * SECONDS_PER_MINUTE + seconds;

    if (totalSeconds < 0) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return (totalSeconds % SECONDS_PER_DAY) / (double)SECONDS_PER_DAY;
  }
View Full Code Here

      result = performBinarySearch(vector, lookupComparer);
    } else {
      result = lookupIndexOfExactValue(lookupComparer, vector);
    }
    if(result < 0) {
      throw new EvaluationException(ErrorEval.NA);
    }
    return result;
  }
View Full Code Here

      return new ValueEval[] { re.getInnerValueEval(), };
    }
    if (eval instanceof AreaEval) {
      AreaEval ae = (AreaEval) eval;
      if(!ae.isColumn() && !ae.isRow()) {
        throw new EvaluationException(ErrorEval.NA);
      }
      return ae.getValues();
    }
   
    // Error handling for lookup_range arg is also unusual
    if(eval instanceof NumericValueEval) {
      throw new EvaluationException(ErrorEval.NA);
    }
    if (eval instanceof StringEval) {
      StringEval se = (StringEval) eval;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        // plain string
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // else looks like a number
      throw new EvaluationException(ErrorEval.NA);
    }
    throw new RuntimeException("Unexpected eval type (" + eval.getClass().getName() + ")");
  }
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.