Examples of Ptg


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

    private void serializePtgs(byte [] data, int offset) {
        int pos = offset;

        for (int k = 0; k < field_13_name_definition.size(); k++) {
            Ptg ptg = ( Ptg ) field_13_name_definition.get(k);

            ptg.writeBytes(data, pos);
            pos += ptg.getSize();
        }
    }
View Full Code Here

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

    /** gets the extern sheet number
     * @return extern sheet index
     */
    public short getExternSheetNumber(){
        if (field_13_name_definition == null) return 0;
        Ptg ptg = (Ptg) field_13_name_definition.peek();
        short result = 0;

        if (ptg.getClass() == Area3DPtg.class){
            result = ((Area3DPtg) ptg).getExternSheetIndex();

        } else if (ptg.getClass() == Ref3DPtg.class){
            result = ((Ref3DPtg) ptg).getExternSheetIndex();
        }

        return result;
    }
View Full Code Here

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

    /** sets the extern sheet number
     * @param externSheetNumber extern sheet number
     */
    public void setExternSheetNumber(short externSheetNumber){
        Ptg ptg;

        if (field_13_name_definition == null || field_13_name_definition.isEmpty()){
            field_13_name_definition = new Stack();
            ptg = createNewPtg();
        } else {
            ptg = (Ptg) field_13_name_definition.peek();
        }

        if (ptg.getClass() == Area3DPtg.class){
            ((Area3DPtg) ptg).setExternSheetIndex(externSheetNumber);

        } else if (ptg.getClass() == Ref3DPtg.class){
            ((Ref3DPtg) ptg).setExternSheetIndex(externSheetNumber);
        }

    }
View Full Code Here

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

        }

    }

    private Ptg createNewPtg(){
        Ptg ptg = new Area3DPtg();
        field_13_name_definition.push(ptg);

        return ptg;
    }
View Full Code Here

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

    /** gets the reference , the area only (range)
     * @return area reference
     */
    public String getAreaReference(Workbook book){
        if (field_13_name_definition == null) return "#REF!";
        Ptg ptg = (Ptg) field_13_name_definition.peek();
        String result = "";

        if (ptg.getClass() == Area3DPtg.class){
            result = ptg.toFormulaString(book);

        } else if (ptg.getClass() == Ref3DPtg.class){
            result = ptg.toFormulaString(book);
        }

        return result;
    }
View Full Code Here

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

     * @param ref area reference
     */
    public void setAreaReference(String ref){
        //Trying to find if what ptg do we need
        RangeAddress ra = new RangeAddress(ref);
        Ptg oldPtg;
        Ptg ptg;

        if (field_13_name_definition==null ||field_13_name_definition.isEmpty()){
            field_13_name_definition = new Stack();
            oldPtg = createNewPtg();
        } else {
            //Trying to find extern sheet index
            oldPtg = (Ptg) field_13_name_definition.pop();
        }

        short externSheetIndex = 0;

        if (oldPtg.getClass() == Area3DPtg.class){
            externSheetIndex =  ((Area3DPtg) oldPtg).getExternSheetIndex();

        } else if (oldPtg.getClass() == Ref3DPtg.class){
            externSheetIndex =  ((Ref3DPtg) oldPtg).getExternSheetIndex();
        }

        if (ra.hasRange()) {
            ptg = new Area3DPtg();
            ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex);
            ((Area3DPtg) ptg).setArea(ref);
            this.setDefinitionTextLength((short)ptg.getSize());
        } else {
            ptg = new Ref3DPtg();
            ((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);
            ((Ref3DPtg) ptg).setArea(ref);
            this.setDefinitionTextLength((short)ptg.getSize());
        }

        field_13_name_definition.push(ptg);

    }
View Full Code Here

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

        Stack stack = new Stack();
        int   pos           = start_of_expression + offset;
        int   sizeCounter   = 0;
        try {
            while (sizeCounter < size) {
                Ptg ptg = Ptg.createPtg(data, pos);

                pos += ptg.getSize();
                sizeCounter += ptg.getSize();
                stack.push(ptg);
                field_13_raw_name_definition=new byte[size];
                System.arraycopy(data,offset,field_13_raw_name_definition,0,size);
            }
        } catch (java.lang.UnsupportedOperationException uoe) {
View Full Code Here

Examples of org.apache.poi.hssf.record.formula.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 = 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);
            }
View Full Code Here

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

   * function Ptg which has been changed from default 'V' to 'A' type (due to requirements on
   * the function return value).
   */
  private void transformNode(ParseNode node, byte desiredOperandClass,
      boolean callerForceArrayFlag) {
    Ptg token = node.getToken();
    ParseNode[] children = node.getChildren();
    boolean isSimpleValueFunc = isSimpleValueFunction(token);

    if (isSimpleValueFunc) {
      boolean localForceArray = desiredOperandClass == Ptg.CLASS_ARRAY;
      for (int i = 0; i < children.length; i++) {
        transformNode(children[i], desiredOperandClass, localForceArray);
      }
      setSimpleValueFuncClass((AbstractFunctionPtg) token, desiredOperandClass, callerForceArrayFlag);
      return;
    }

    if (isSingleArgSum(token)) {
      // Need to process the argument of SUM with transformFunctionNode below
      // so make a dummy FuncVarPtg for that call.
      token = FuncVarPtg.SUM;
      // Note - the tAttrSum token (node.getToken()) is a base
      // token so does not need to have its operand class set
    }
    if (token instanceof ValueOperatorPtg || token instanceof ControlPtg
        || token instanceof MemFuncPtg
        || token instanceof MemAreaPtg
        || token instanceof UnionPtg) {
      // Value Operator Ptgs and Control are base tokens, so token will be unchanged
      // but any child nodes are processed according to desiredOperandClass and callerForceArrayFlag

      // As per OOO documentation Sec 3.2.4 "Token Class Transformation", "Step 1"
      // All direct operands of value operators that are initially 'R' type will
      // be converted to 'V' type.
      byte localDesiredOperandClass = desiredOperandClass == Ptg.CLASS_REF ? Ptg.CLASS_VALUE : desiredOperandClass;
      for (int i = 0; i < children.length; i++) {
        transformNode(children[i], localDesiredOperandClass, callerForceArrayFlag);
      }
      return;
    }
    if (token instanceof AbstractFunctionPtg) {
      transformFunctionNode((AbstractFunctionPtg) token, children, desiredOperandClass, callerForceArrayFlag);
      return;
    }
    if (children.length > 0) {
      if (token == RangePtg.instance) {
        // TODO is any token transformation required under the various ref operators?
        return;
      }
      throw new IllegalStateException("Node should not have any children");
    }

    if (token.isBaseToken()) {
      // nothing to do
      return;
    }
    token.setClass(transformClass(token.getPtgClass(), desiredOperandClass, callerForceArrayFlag));
  }
View Full Code Here

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

  }

  private static void confirmUnary(String formulaText, double val, Class<?>...expectedTokenTypes) {
    Ptg[] ptgs = parseFormula(formulaText);
    confirmTokenClasses(ptgs, expectedTokenTypes);
    Ptg ptg0 = ptgs[0];
    if (ptg0 instanceof IntPtg) {
      IntPtg intPtg = (IntPtg) ptg0;
      assertEquals((int)val, intPtg.getValue());
    } else if (ptg0 instanceof NumberPtg) {
      NumberPtg numberPtg = (NumberPtg) ptg0;
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.