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

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


    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

   *
   * @param v
   */
  public static double evaluate(double[] v) throws EvaluationException {
    if (v.length < 2) {
      throw new EvaluationException(ErrorEval.NA);
    }

    // very naive impl, may need to be optimized
    int[] counts = new int[v.length];
    Arrays.fill(counts, 1);
    for (int i = 0, iSize = v.length; i < iSize; i++) {
      for (int j = i + 1, jSize = v.length; j < jSize; j++) {
        if (v[i] == v[j])
          counts[i]++;
      }
    }
    double maxv = 0;
    int maxc = 0;
    for (int i = 0, iSize = counts.length; i < iSize; i++) {
      if (counts[i] > maxc) {
        maxv = v[i];
        maxc = counts[i];
      }
    }
    if (maxc > 1) {
      return maxv;
    }
    throw new EvaluationException(ErrorEval.NA);

  }
View Full Code Here

  }

  private static void collectValue(Eval arg, List<Double> temp, boolean mustBeNumber)
      throws EvaluationException {
    if (arg instanceof ErrorEval) {
      throw new EvaluationException((ErrorEval) arg);
    }
    if (arg == BlankEval.INSTANCE || arg instanceof BoolEval || arg instanceof StringEval) {
      if (mustBeNumber) {
        throw EvaluationException.invalidValue();
      }
View Full Code Here

      return ((AreaEval) eval).offset(0, aeRange.getHeight()-1, 0, aeRange.getWidth()-1);
    }
    if (eval instanceof RefEval) {
      return ((RefEval)eval).offset(0, aeRange.getHeight()-1, 0, aeRange.getWidth()-1);
    }
    throw new EvaluationException(ErrorEval.VALUE_INVALID);
  }
View Full Code Here

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

        atleastOneNonBlank = true;
      }
    }

    if (!atleastOneNonBlank) {
      throw new EvaluationException(ErrorEval.VALUE_INVALID);
    }
    return result;
  }
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(Eval[] 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(Eval[] 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

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.