Package org.apache.poi.ss.formula.eval

Examples of org.apache.poi.ss.formula.eval.ValueEval


public class Rept extends Fixed2ArgFunction  {


    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval text, ValueEval number_times) {

        ValueEval veText1;
        try {
            veText1 = OperandResolver.getSingleValue(text, srcRowIndex, srcColumnIndex);
        } catch (EvaluationException e) {
            return e.getErrorEval();
        }
View Full Code Here


    private final static long MIN_VALUE = Long.parseLong("-512");
    private final static long MAX_VALUE = Long.parseLong("512");
    private final static int DEFAULT_PLACES_VALUE = 10;

    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval placesVE) {
        ValueEval veText1;
        try {
            veText1 = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
        } catch (EvaluationException e) {
            return e.getErrorEval();
        }
        String strText1 = OperandResolver.coerceValueToString(veText1);
        Double number = OperandResolver.parseDouble(strText1);

        //If this number argument is non numeric, this function returns the #VALUE! error value.
        if (number == null) {
            return ErrorEval.VALUE_INVALID;
        }

        //If number < -512 or if number > 512, this function returns the #NUM! error value.
        if (number.longValue() < MIN_VALUE || number.longValue() > MAX_VALUE) {
            return ErrorEval.NUM_ERROR;
        }

        int placesNumber;
        if (number < 0 || placesVE == null) {
            placesNumber = DEFAULT_PLACES_VALUE;
        } else {
            ValueEval placesValueEval;
            try {
                placesValueEval = OperandResolver.getSingleValue(placesVE, srcRowIndex, srcColumnIndex);
            } catch (EvaluationException e) {
                return e.getErrorEval();
            }
View Full Code Here

    int nIncomingArgs = args.length;
    if(nIncomingArgs < 1) {
      throw new RuntimeException("function name argument missing");
    }

    ValueEval nameArg = args[0];
    String functionName;
    if (nameArg instanceof FunctionNameEval) {
      functionName = ((FunctionNameEval) nameArg).getFunctionName();
    } else {
      throw new RuntimeException("First argument should be a NameEval, but got ("
          + nameArg.getClass().getName() + ")");
    }
    FreeRefFunction targetFunc = ec.findUserDefinedFunction(functionName);
    if (targetFunc == null) {
      throw new NotImplementedFunctionException(functionName);
    }
View Full Code Here

    ErrorEval firstYerr = null;
    boolean accumlatedSome = false;
    double result = 0.0;

    for (int i = 0; i < size; i++) {
      ValueEval vx = x.getItem(i);
      ValueEval vy = y.getItem(i);
      if (vx instanceof ErrorEval) {
        if (firstXerr == null) {
          firstXerr = (ErrorEval) vx;
          continue;
        }
View Full Code Here


    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval formVE) {
        int number = 0;
        try {
            ValueEval ve = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
            number = OperandResolver.coerceValueToInt(ve);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }
        if (number < 0) {
            return ErrorEval.VALUE_INVALID;
        }
        if (number > 3999) {
            return ErrorEval.VALUE_INVALID;
        }
        if (number == 0) {
            return new StringEval("");
        }

        int form = 0;
        try {
            ValueEval ve = OperandResolver.getSingleValue(formVE, srcRowIndex, srcColumnIndex);
            form = OperandResolver.coerceValueToInt(ve);
        } catch (EvaluationException e) {
            return ErrorEval.NUM_ERROR;
        }
View Full Code Here

  /**
   * Returns a CellValue wrapper around the supplied ValueEval instance.
   * @param cell
   */
  private CellValue evaluateFormulaCellValue(Cell cell) {
    ValueEval eval = _bookEvaluator.evaluate(new HSSFEvaluationCell((HSSFCell)cell));
    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof NumericValueEval) {
      NumericValueEval ne = (NumericValueEval) eval;
      return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof StringValueEval) {
      StringValueEval ne = (StringValueEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
  }
View Full Code Here

  public static int resolveRowOrColIndexArg(ValueEval rowColIndexArg, int srcCellRow, int srcCellCol) throws EvaluationException {
    if(rowColIndexArg == null) {
      throw new IllegalArgumentException("argument must not be null");
    }

    ValueEval veRowColIndexArg;
    try {
      veRowColIndexArg = OperandResolver.getSingleValue(rowColIndexArg, srcCellRow, (short)srcCellCol);
    } catch (EvaluationException e) {
      // All errors get translated to #REF!
      throw EvaluationException.invalidRef();
View Full Code Here

   * Resolves the last (optional) parameter (<b>range_lookup</b>) to the VLOOKUP and HLOOKUP functions.
   * @param rangeLookupArg must not be <code>null</code>
   */
  public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol) throws EvaluationException {

    ValueEval valEval = OperandResolver.getSingleValue(rangeLookupArg, srcCellRow, srcCellCol);
    if(valEval instanceof BlankEval) {
      // Tricky:
      // fourth arg supplied but evaluates to blank
      // this does not get the default value
      return false;
    }
    if(valEval instanceof BoolEval) {
      // Happy day flow
      BoolEval boolEval = (BoolEval) valEval;
      return boolEval.getBooleanValue();
    }

    if (valEval instanceof StringEval) {
      String stringValue = ((StringEval) valEval).getStringValue();
      if(stringValue.length() < 1) {
        // More trickiness:
        // Empty string is not the same as BlankEval.  It causes #VALUE! error
        throw EvaluationException.invalidValue();
      }
      // TODO move parseBoolean to OperandResolver
      Boolean b = Countif.parseBoolean(stringValue);
      if(b != null) {
        // string converted to boolean OK
        return b.booleanValue();
      }
      // Even more trickiness:
      // Note - even if the StringEval represents a number value (for example "1"),
      // Excel does not resolve it to a boolean.
      throw EvaluationException.invalidValue();
      // This is in contrast to the code below,, where NumberEvals values (for
      // example 0.01) *do* resolve to equivalent boolean values.
    }
    if (valEval instanceof NumericValueEval) {
      NumericValueEval nve = (NumericValueEval) valEval;
      // zero is FALSE, everything else is TRUE
      return 0.0 != nve.getNumberValue();
    }
    throw new RuntimeException("Unexpected eval type (" + valEval.getClass().getName() + ")");
  }
View Full Code Here

    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval real_num, ValueEval i_num) {
        return this.evaluate(srcRowIndex, srcColumnIndex, real_num, i_num, new StringEval(DEFAULT_SUFFIX));
    }

    public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval real_num, ValueEval i_num, ValueEval suffix) {
        ValueEval veText1;
        try {
            veText1 = OperandResolver.getSingleValue(real_num, srcRowIndex, srcColumnIndex);
        } catch (EvaluationException e) {
            return e.getErrorEval();
        }
        double realNum = 0;
        try {
            realNum = OperandResolver.coerceValueToDouble(veText1);
        } catch (EvaluationException e) {
            return ErrorEval.VALUE_INVALID;
        }

        ValueEval veINum;
        try {
            veINum = OperandResolver.getSingleValue(i_num, srcRowIndex, srcColumnIndex);
        } catch (EvaluationException e) {
            return e.getErrorEval();
        }
View Full Code Here

  /**
   * Returns a CellValue wrapper around the supplied ValueEval instance.
   * @param eval
   */
  private CellValue evaluateFormulaCellValue(Cell cell) {
    ValueEval eval = _bookEvaluator.evaluate(new HSSFEvaluationCell((HSSFCell)cell));
    if (eval instanceof NumberEval) {
      NumberEval ne = (NumberEval) eval;
      return new CellValue(ne.getNumberValue());
    }
    if (eval instanceof BoolEval) {
      BoolEval be = (BoolEval) eval;
      return CellValue.valueOf(be.getBooleanValue());
    }
    if (eval instanceof StringEval) {
      StringEval ne = (StringEval) eval;
      return new CellValue(ne.getStringValue());
    }
    if (eval instanceof ErrorEval) {
      return CellValue.getError(((ErrorEval)eval).getErrorCode());
    }
    throw new RuntimeException("Unexpected eval class (" + eval.getClass().getName() + ")");
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.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.