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

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


    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = evaluateFormula(ptgs);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
  }
View Full Code Here


  private static void confirmRefErr(Ptg ptg) {
    Ptg[] ptgs = {
      ptg,
    };

    ValueEval result = evaluateFormula(ptgs);
    assertEquals(ErrorEval.REF_INVALID, result);
  }
View Full Code Here

    Ptg[] ptgs = {
      new IntPtg(42),
      AttrPtg.SUM,
    };

    ValueEval result = evaluateFormula(ptgs);
    assertEquals(42, ((NumberEval)result).getNumberValue(), 0.0);
  }
View Full Code Here

      AreaEval ae = (AreaEval) operand;
      int width = ae.getWidth();
      int height = ae.getHeight();
      for (int rrIx=0; rrIx<height; rrIx++) {
        for (int rcIx=0; rcIx<width; rcIx++) {
          ValueEval ve = ae.getRelativeValue(rrIx, rcIx);
          collectValue(ve, true, temp);
        }
      }
      return;
    }
View Full Code Here

    boolean matchExact = match_type == 0;
    // Note - Excel does not strictly require -1 and +1
    boolean findLargestLessThanOrEqual = match_type > 0;

    try {
      ValueEval lookupValue = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
      ValueVector lookupRange = evaluateLookupRange(arg1);
      int index = findIndexOfValue(lookupValue, lookupRange, matchExact, findLargestLessThanOrEqual);
      return new NumberEval(index + 1); // +1 to convert to 1-based
    } catch (EvaluationException e) {
      return e.getErrorEval();
View Full Code Here



  private static double evaluateMatchTypeArg(ValueEval arg, int srcCellRow, int 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

  public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
      ValueEval arg2, ValueEval arg3) {
    try {
      // Evaluation order:
      // arg0 lookup_value, arg1 table_array, arg3 range_lookup, find lookup value, arg2 row_index, fetch result
      ValueEval lookupValue = OperandResolver.getSingleValue(arg0, srcRowIndex, srcColumnIndex);
      AreaEval tableArray = LookupUtils.resolveTableArrayArg(arg1);
      boolean isRangeLookup = LookupUtils.resolveRangeLookupArg(arg3, srcRowIndex, srcColumnIndex);
      int colIndex = LookupUtils.lookupIndexOfValue(lookupValue, LookupUtils.createRowVector(tableArray, 0), isRangeLookup);
      int rowIndex = LookupUtils.resolveRowOrColIndexArg(arg2, srcRowIndex, srcColumnIndex);
      ValueVector resultCol = createResultColumnVector(tableArray, rowIndex);
View Full Code Here

    int maxN = args.length;

    if(maxN < 1) {
      return ErrorEval.VALUE_INVALID;
    }
    ValueEval firstArg = args[0];
    try {
      if(firstArg instanceof NumericValueEval) {
        return evaluateSingleProduct(args);
      }
      if(firstArg instanceof RefEval) {
        return evaluateSingleProduct(args);
      }
      if(firstArg instanceof AreaEval) {
        AreaEval ae = (AreaEval) firstArg;
        if(ae.isRow() && ae.isColumn()) {
          return evaluateSingleProduct(args);
        }
        return evaluateAreaSumProduct(args);
      }
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
    throw new RuntimeException("Invalid arg type for SUMPRODUCT: ("
        + firstArg.getClass().getName() + ")");
  }
View Full Code Here

    return new NumberEval(term);
  }

  private static double getScalarValue(ValueEval arg) throws EvaluationException {

    ValueEval eval;
    if (arg instanceof RefEval) {
      RefEval re = (RefEval) arg;
      eval = re.getInnerValueEval();
    } else {
      eval = arg;
View Full Code Here

  private static void throwFirstError(AreaEval areaEval) throws EvaluationException {
    int height = areaEval.getHeight();
    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.ValueEval

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.