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

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


      LinearOffsetRange orRow, LinearOffsetRange orCol) throws EvaluationException {
    LinearOffsetRange absRows = orRow.normaliseAndTranslate(baseRef.getFirstRowIndex());
    LinearOffsetRange absCols = orCol.normaliseAndTranslate(baseRef.getFirstColumnIndex());
   
    if(absRows.isOutOfBounds(0, LAST_VALID_ROW_INDEX)) {
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    if(absCols.isOutOfBounds(0, LAST_VALID_COLUMN_INDEX)) {
      throw new EvaluationException(ErrorEval.REF_INVALID);
    }
    return baseRef.offset(orRow.getFirstIndex(), orRow.getLastIndex(), orCol.getFirstIndex(), orCol.getLastIndex());
  }
View Full Code Here


    }
    if(eval instanceof AreaEval) {
      return new BaseRef((AreaEval)eval);
    }
    if (eval instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) eval);
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
  }
View Full Code Here

    }
    if (ve instanceof StringEval) {
      StringEval se = (StringEval) ve;
      Double d = OperandResolver.parseDouble(se.getStringValue());
      if(d == null) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      return d.doubleValue();
    }
    if (ve instanceof BoolEval) {
      // in the context of OFFSET, booleans resolve to 0 and 1.
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);
    }

    if (!(eval instanceof ValueEval)) {
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

    if(ve instanceof BlankEval || ve == null) {
      // TODO - shouldn't BlankEval.INSTANCE be used always instead of null?
      // null seems to occur when the blank cell is part of an area ref (but not reliably)
      if(isScalarProduct) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      return 0;
    }
   
    if(ve instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval)ve);
    }
    if(ve instanceof StringEval) {
      if(isScalarProduct) {
        throw new EvaluationException(ErrorEval.VALUE_INVALID);
      }
      // Note for area SUMPRODUCTs, string values are interpreted as zero
      // even if they would parse as valid numeric values
      return 0;
    }
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

      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(ValueEval arg, int srcCellRow, short srcCellCol)
      throws EvaluationException {
    ValueEval 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

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.