Package org.apache.poi.ss.formula.ptg

Examples of org.apache.poi.ss.formula.ptg.Ptg


    Stack<ValueEval> stack = new Stack<ValueEval>();
    for (int i = 0, iSize = ptgs.length; i < iSize; i++) {

      // since we don't know how to handle these yet :(
      Ptg ptg = ptgs[i];
      if (ptg instanceof AttrPtg) {
        AttrPtg attrPtg = (AttrPtg) ptg;
        if (attrPtg.isSum()) {
          // Excel prefers to encode 'SUM()' as a tAttr token, but this evaluator
          // expects the equivalent function token
          ptg = FuncVarPtg.SUM;
        }
        if (attrPtg.isOptimizedChoose()) {
          ValueEval arg0 = stack.pop();
          int[] jumpTable = attrPtg.getJumpTable();
          int dist;
          int nChoices = jumpTable.length;
          try {
            int switchIndex = Choose.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
            if (switchIndex<1 || switchIndex > nChoices) {
              stack.push(ErrorEval.VALUE_INVALID);
              dist = attrPtg.getChooseFuncOffset() + 4; // +4 for tFuncFar(CHOOSE)
            } else {
              dist = jumpTable[switchIndex-1];
            }
          } catch (EvaluationException e) {
            stack.push(e.getErrorEval());
            dist = attrPtg.getChooseFuncOffset() + 4; // +4 for tFuncFar(CHOOSE)
          }
          // Encoded dist for tAttrChoose includes size of jump table, but
          // countTokensToBeSkipped() does not (it counts whole tokens).
          dist -= nChoices*2+2; // subtract jump table size
          i+= countTokensToBeSkipped(ptgs, i, dist);
          continue;
        }
        if (attrPtg.isOptimizedIf()) {
          ValueEval arg0 = stack.pop();
          boolean evaluatedPredicate;
          try {
            evaluatedPredicate = IfFunc.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
          } catch (EvaluationException e) {
            stack.push(e.getErrorEval());
            int dist = attrPtg.getData();
            i+= countTokensToBeSkipped(ptgs, i, dist);
            attrPtg = (AttrPtg) ptgs[i];
            dist = attrPtg.getData()+1;
            i+= countTokensToBeSkipped(ptgs, i, dist);
            continue;
          }
          if (evaluatedPredicate) {
            // nothing to skip - true param folows
          } else {
            int dist = attrPtg.getData();
            i+= countTokensToBeSkipped(ptgs, i, dist);
            Ptg nextPtg = ptgs[i+1];
            if (ptgs[i] instanceof AttrPtg && nextPtg instanceof FuncVarPtg) {
              // this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
              i++;
              stack.push(BoolEval.FALSE);
            }
View Full Code Here


            NameRecord origNameRecord = workbook.getNameRecord(filterDbNameIndex);
            // copy original formula but adjust 3D refs to the new external sheet index
            int newExtSheetIx = workbook.checkExternSheet(newSheetIndex);
            Ptg[] ptgs = origNameRecord.getNameDefinition();
            for (int i=0; i< ptgs.length; i++) {
                Ptg ptg = ptgs[i];

                if (ptg instanceof Area3DPtg) {
                    Area3DPtg a3p = (Area3DPtg) ((OperandPtg) ptg).copy();
                    a3p.setExternSheetIndex(newExtSheetIx);
                    ptgs[i] = a3p;
View Full Code Here

    sb.append("    .ix      = ").append(field_2_ixals).append("\n");
    sb.append("    .name    = ").append(field_4_name).append("\n");
    if(field_5_name_definition != null) {
            Ptg[] ptgs = field_5_name_definition.getTokens();
            for (int i = 0; i < ptgs.length; i++) {
                Ptg ptg = ptgs[i];
                sb.append(ptg.toString()).append(ptg.getRVAType()).append("\n");
            }
    }
    sb.append("[/EXTERNALNAME]\n");
    return sb.toString();
  }
View Full Code Here

    }
    return result;
  }

  private static ParseNode augmentWithMemPtg(ParseNode root) {
    Ptg memPtg;
    if (needsMemFunc(root)) {
      memPtg = new MemFuncPtg(root.getEncodedSize());
    } else {
      memPtg = new MemAreaPtg(root.getEncodedSize());
    }
View Full Code Here

   *  a defined name, a 3D reference, or an external reference (and no error occurs),
   *  a tMemFunc token is used"
   *
   */
  private static boolean needsMemFunc(ParseNode root) {
    Ptg token = root.getToken();
    if (token instanceof AbstractFunctionPtg) {
      return true;
    }
    if (token instanceof ExternSheetReferenceToken) { // 3D refs
      return true;
View Full Code Here

  /**
   * @return <code>false</code> if sub-expression represented the specified ParseNode definitely
   * cannot appear on either side of the range (':') operator
   */
  private static boolean isValidRangeOperand(ParseNode a) {
    Ptg tkn = a.getToken();
    // Note - order is important for these instance-of checks
    if (tkn instanceof OperandPtg) {
      // notably cell refs and area refs
      return true;
    }
View Full Code Here

                    String name = parseAsName();
                    if (name.length() == 0) {
                        throw new FormulaParseException("Cell reference or Named Range "
                                + "expected after sheet name at index " + _pointer + ".");
                    }
                    Ptg nameXPtg = _book.getNameXPtg(name, sheetIden);
                    if (nameXPtg == null) {
                        throw new FormulaParseException("Specified name '" + name +
                                "' for sheet " + sheetIden.asFormulaString() + " not found");
                    }
                    return new ParseNode(nameXPtg);
View Full Code Here

   * @param part1
   * @param part2 may be <code>null</code>
   */
  private ParseNode createAreaRefParseNode(SheetIdentifier sheetIden, SimpleRangePart part1,
      SimpleRangePart part2) throws FormulaParseException {
    Ptg ptg;
    if (part2 == null) {
      CellReference cr = part1.getCellReference();
      if (sheetIden == null) {
        ptg = new RefPtg(cr);
      } else {
View Full Code Here

   * Excel function, and has not been encountered before.
   *
   * @param name case preserved function name (as it was entered/appeared in the formula).
   */
  private ParseNode function(String name) {
    Ptg nameToken = null;
    if(!AbstractFunctionPtg.isBuiltInFunctionName(name)) {
      // user defined function
      // in the token tree, the name is more or less the first argument

      if (_book == null) {
View Full Code Here

    ParseNode factor = powerFactor();

    if (numberFollows) {
      // + or - directly next to a number is parsed with the number

      Ptg token = factor.getToken();
      if (token instanceof NumberPtg) {
        if (isPlus) {
          return factor;
        }
        token = new NumberPtg(-((NumberPtg)token).getValue());
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.formula.ptg.Ptg

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.