Examples of AttrPtg


Examples of org.apache.poi.hssf.record.formula.AttrPtg

        fp.parse();
        Ptg[] asts = fp.getRPNPtg();
        assertEquals(7, asts.length);

        BoolPtg flag  = (BoolPtg) asts[0];
    AttrPtg funif = (AttrPtg) asts[1];
        StringPtg y = (StringPtg) asts[2];
    AttrPtg goto1 = (AttrPtg) asts[3];
        StringPtg n = (StringPtg) asts[4];


        assertEquals(true, flag.getValue());
        assertEquals("Y", y.getValue());
        assertEquals("N", n.getValue());
        assertEquals("IF", funif.toFormulaString((Workbook) null));
        assertTrue("Goto ptg exists", goto1.isGoto());
    }
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    assertEquals(9, asts.length);
   
    IntPtg op1 = (IntPtg) asts[0];
    IntPtg op2 = (IntPtg) asts[1];
    EqualPtg eq = (EqualPtg) asts[2];   
    AttrPtg ifPtg = (AttrPtg) asts[3];
    IntPtg res1 = (IntPtg) asts[4];
       
    AttrPtg ptgGoto= (AttrPtg) asts[5];   
    assertEquals("Goto 1 Length", (short)10, ptgGoto.getData());
   
    IntPtg res2 = (IntPtg) asts[6];   
    AttrPtg ptgGoto2 = (AttrPtg) asts[7];   
    assertEquals("Goto 2 Length", (short)3, ptgGoto2.getData());
   
    assertEquals("If FALSE offset", (short)7, ifPtg.getData());
   
    FuncVarPtg funcPtg = (FuncVarPtg)asts[8];
   
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    fp.parse();
    Ptg[] asts = fp.getRPNPtg();
    assertEquals("11 Ptgs expected", 11, asts.length);

    assertTrue("IF Attr set correctly", (asts[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg)asts[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());
   
    assertTrue("Average Function set correctly", (asts[5] instanceof FuncVarPtg));
   
             
  }
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    fp.parse();
    Ptg[] asts = fp.getRPNPtg();
    assertEquals("7 Ptgs expected", 7, asts.length);

    assertTrue("IF Attr set correctly", (asts[3] instanceof AttrPtg));
    AttrPtg ifFunc = (AttrPtg)asts[3];
    assertTrue("It is not an if", ifFunc.isOptimizedIf());
   
    assertTrue("Single Value is not an IntPtg", (asts[4] instanceof IntPtg));
    IntPtg intPtg = (IntPtg)asts[4];
    assertEquals("Result", (short)10, intPtg.getValue());
   
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

  public void testSpaceAtStartOfFormula() {
    // Simulating cell formula of "= 4" (note space)
    // The same Ptg array can be observed if an excel file is saved with that exact formula

    AttrPtg spacePtg = AttrPtg.createSpace(AttrPtg.SpaceType.SPACE_BEFORE, 1);
    Ptg[] ptgs = { spacePtg, new IntPtg(4), };
    String formulaString;
    try {
      formulaString = FormulaParser.toFormulaString(null, ptgs);
    } catch (IllegalStateException e) {
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    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 = If.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);
            }
          }
          continue;
        }
        if (attrPtg.isSkip()) {
          int dist = attrPtg.getData()+1;
          i+= countTokensToBeSkipped(ptgs, i, dist);
          if (stack.peek() == MissingArgEval.instance) {
            stack.pop();
            stack.push(BlankEval.instance);
          }
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    token.setClass(transformClass(token.getPtgClass(), desiredOperandClass, callerForceArrayFlag));
  }

  private static boolean isSingleArgSum(Ptg token) {
    if (token instanceof AttrPtg) {
      AttrPtg attrPtg = (AttrPtg) token;
      return attrPtg.isSum();
    }
    return false;
  }
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

  public void testSpaceAtStartOfFormula() {
    // Simulating cell formula of "= 4" (note space)
    // The same Ptg array can be observed if an excel file is saved with that exact formula

    AttrPtg spacePtg = AttrPtg.createSpace(AttrPtg.SpaceType.SPACE_BEFORE, 1);
    Ptg[] ptgs = { spacePtg, new IntPtg(4), };
    String formulaString;
    try {
      formulaString = toFormulaString(ptgs);
    } catch (IllegalStateException e) {
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

    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
          byte nArgs = 1// tAttrSum always has 1 parameter
          ptg = new FuncVarPtg("SUM", nArgs);
        }
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.AttrPtg

        fp.parse();
        Ptg[] asts = fp.getRPNPtg();
        assertEquals(7, asts.length);

        BoolPtg flag  = (BoolPtg) asts[0];
    AttrPtg funif = (AttrPtg) asts[1];
        StringPtg y = (StringPtg) asts[2];
    AttrPtg goto1 = (AttrPtg) asts[3];
        StringPtg n = (StringPtg) asts[4];


        assertEquals(true, flag.getValue());
        assertEquals("Y", y.getValue());
        assertEquals("N", n.getValue());
        assertEquals("IF", funif.toFormulaString((HSSFWorkbook) null));
        assertTrue("Goto ptg exists", goto1.isGoto());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.