示例#1
0
 public PtgFunc(FtabValues fTab, PtgDataType dt = PtgDataType.REFERENCE, bool setHighBit = false) : base(PtgNumber.PtgFunc, dt, setHighBit)
 {
     this.Data    = "";
     this.Length  = 3;
     this.popSize = 1;
     this.tab     = Convert.ToUInt16(fTab);
     this.type    = PtgType.Operator;
 }
示例#2
0
        public PtgFuncVar(FtabValues ftab, int cparams, PtgDataType dt = PtgDataType.REFERENCE) : base(PtgNumber.PtgFuncVar, dt)
        {
            this.Length = 4;
            this.Data   = "";
            this.type   = PtgType.Operator;

            this.cparams  = (byte)cparams;
            this.tab      = (ushort)ftab;
            this.fCelFunc = false;
            this.popSize  = (uint)this.cparams;
        }
示例#3
0
        public static int GetParamCountFromFtabValue(FtabValues value)
        {
            switch (value)
            {
            case FtabValues.NEXT:
            case FtabValues.ACTIVE_CELL:
            case FtabValues.NA:
            case FtabValues.PI:
            case FtabValues.TRUE:
            case FtabValues.FALSE:
            case FtabValues.RAND:
            case FtabValues.NOW:
            case FtabValues.STEP:
            case FtabValues.CALLER:
            case FtabValues.SELECTION:
            case FtabValues.BREAK:
            case FtabValues.TODAY:
            case FtabValues.ELSE:
            case FtabValues.END_IF:
            case FtabValues.LAST_ERROR:
            case FtabValues.GROUP:
                return(0);

            case FtabValues.ISERROR:
            case FtabValues.WHILE:
            case FtabValues.GOTO:
            case FtabValues.LEN:
            case FtabValues.ISNA:
            case FtabValues.ISNUMBER:
            case FtabValues.GET_WORKSPACE:
            case FtabValues.CHAR:
            case FtabValues.SIN:
            case FtabValues.COS:
            case FtabValues.TAN:
            case FtabValues.ATAN:
            case FtabValues.SQRT:
            case FtabValues.LN:
            case FtabValues.LOG10:
            case FtabValues.ABS:
            case FtabValues.INT:
            case FtabValues.SIGN:
            case FtabValues.VALUE:
            case FtabValues.NOT:
            case FtabValues.DAY:
            case FtabValues.MONTH:
            case FtabValues.YEAR:
            case FtabValues.HOUR:
            case FtabValues.MINUTE:
            case FtabValues.SECOND:
            case FtabValues.AREAS:
            case FtabValues.ROWS:
            case FtabValues.COLUMNS:
            case FtabValues.TRANSPOSE:
            case FtabValues.TYPE:
            case FtabValues.DEREF:
            case FtabValues.ASIN:
            case FtabValues.ACOS:
            case FtabValues.ISREF:
            case FtabValues.GET_FORMULA:
            case FtabValues.LOWER:
            case FtabValues.UPPER:
            case FtabValues.PROPER:
            case FtabValues.TRIM:
            case FtabValues.CODE:
            case FtabValues.ISERR:
            case FtabValues.ISTEXT:
            case FtabValues.ISBLANK:
            case FtabValues.T:
            case FtabValues.N:
            case FtabValues.FCLOSE:
            case FtabValues.FSIZE:
            case FtabValues.FREADLN:
            case FtabValues.DATEVALUE:
            case FtabValues.TIMEVALUE:
            case FtabValues.DIALOG_BOX:
            case FtabValues.CLEAN:
            case FtabValues.MDETERM:
            case FtabValues.MINVERSE:
            case FtabValues.TERMINATE:
            case FtabValues.FACT:
            case FtabValues.ISNONTEXT:
            case FtabValues.ISLOGICAL:
            case FtabValues.DELETE_BAR:
            case FtabValues.UNREGISTER:
            case FtabValues.LENB:
            case FtabValues.ASC:
            case FtabValues.DBCS:
            case FtabValues.ELSE_IF:
            case FtabValues.SINH:
            case FtabValues.COSH:
            case FtabValues.TANH:
            case FtabValues.ASINH:
            case FtabValues.ACOSH:
            case FtabValues.ATANH:
            case FtabValues.INFO:
            case FtabValues.DELETE_TOOLBAR:
            case FtabValues.RESET_TOOLBAR:
            case FtabValues.EVALUATE:
            case FtabValues.ERROR_TYPE:
            case FtabValues.GAMMALN:
            case FtabValues.EVEN:
            case FtabValues.FISHER:
            case FtabValues.FISHERINV:
            case FtabValues.NORMSDIST:
            case FtabValues.NORMSINV:
            case FtabValues.ODD:
            case FtabValues.RADIANS:
            case FtabValues.DEGREES:
            case FtabValues.COUNTBLANK:
            case FtabValues.OPTIONS_LISTS_GET:
            case FtabValues.DATESTRING:
            case FtabValues.PHONETIC:
            case FtabValues.BAHTTEXT:
            case FtabValues.THAIDAYOFWEEK:
            case FtabValues.THAIDIGIT:
            case FtabValues.THAIMONTHOFYEAR:
            case FtabValues.THAINUMSOUND:
            case FtabValues.THAINUMSTRING:
            case FtabValues.THAISTRINGLENGTH:
            case FtabValues.ISTHAIDIGIT:
            case FtabValues.ROUNDBAHTDOWN:
            case FtabValues.ROUNDBAHTUP:
            case FtabValues.THAIYEAR:
                return(1);

            case FtabValues.ARGUMENT:
            case FtabValues.SET_VALUE:
            case FtabValues.ROUND:
            case FtabValues.ABSREF:
            case FtabValues.REPT:
            case FtabValues.MOD:
            case FtabValues.TEXT:
            case FtabValues.RELREF:
            case FtabValues.ATAN2:
            case FtabValues.EXACT:
            case FtabValues.FREAD:
            case FtabValues.FWRITELN:
            case FtabValues.FWRITE:
            case FtabValues.MMULT:
            case FtabValues.INITIATE:
            case FtabValues.REQUEST:
            case FtabValues.EXECUTE:
            case FtabValues.ROUNDUP:
            case FtabValues.ROUNDDOWN:
            case FtabValues.FREQUENCY:
            case FtabValues.CHIDIST:
            case FtabValues.CHIINV:
            case FtabValues.COMBIN:
            case FtabValues.FLOOR:
            case FtabValues.CEILING:
            case FtabValues.PERMUT:
            case FtabValues.SUMXMY2:
            case FtabValues.SUMX2MY2:
            case FtabValues.SUMX2PY2:
            case FtabValues.CHITEST:
            case FtabValues.CORREL:
            case FtabValues.COVAR:
            case FtabValues.FTEST:
            case FtabValues.INTERCEPT:
            case FtabValues.PEARSON:
            case FtabValues.RSQ:
            case FtabValues.STEYX:
            case FtabValues.SLOPE:
            case FtabValues.LARGE:
            case FtabValues.SMALL:
            case FtabValues.QUARTILE:
            case FtabValues.PERCENTILE:
            case FtabValues.TRIMMEAN:
            case FtabValues.TINV:
            case FtabValues.POWER:
            case FtabValues.COUNTIF:
            case FtabValues.NUMBERSTRING:
                return(2);

            case FtabValues.MID:
            case FtabValues.DCOUNT:
            case FtabValues.DSUM:
            case FtabValues.DAVERAGE:
            case FtabValues.DMIN:
            case FtabValues.DMAX:
            case FtabValues.DSTDEV:
            case FtabValues.DVAR:
            case FtabValues.DATE:
            case FtabValues.TIME:
            case FtabValues.SLN:
            case FtabValues.MIDB:
            case FtabValues.ENABLE_TOOL:
            case FtabValues.PRESS_TOOL:
            case FtabValues.CONFIDENCE:
            case FtabValues.CRITBINOM:
            case FtabValues.EXPONDIST:
            case FtabValues.FDIST:
            case FtabValues.FINV:
            case FtabValues.GAMMAINV:
            case FtabValues.LOGNORMDIST:
            case FtabValues.LOGINV:
            case FtabValues.NEGBINOMDIST:
            case FtabValues.NORMINV:
            case FtabValues.STANDARDIZE:
            case FtabValues.POISSON:
            case FtabValues.TDIST:
            case FtabValues.FORECAST:
            case FtabValues.DATEDIF:
                return(3);

            case FtabValues.REPLACE:
            case FtabValues.SYD:
            case FtabValues.REPLACEB:
            case FtabValues.BINOMDIST:
            case FtabValues.GAMMADIST:
            case FtabValues.HYPGEOMDIST:
            case FtabValues.NORMDIST:
            case FtabValues.WEIBULL:
            case FtabValues.TTEST:
            case FtabValues.ISPMT:
                return(4);

            default:
                throw new NotImplementedException(
                          "Arg Count for " + value.ToString() + "not implemented.");
            }
        }
示例#4
0
        /// <summary>
        /// This static method is used to convert the ptgStack to the infixnotation
        /// This method changes every Ptg***N** PtgRecord from a shared formula
        /// </summary>
        /// <param name="stack"></param>
        /// <param name="xlsContext"></param>
        /// <param name="rw">Row from the shared formula</param>
        /// <param name="col">Column from  the shared formula</param>
        /// <returns></returns>
        public static string mapFormula(Stack <AbstractPtg> stack, ExcelContext xlsContext, int rw, int col)
        {
            Stack <string> resultStack = new Stack <string>();

            try
            {
                Stack <AbstractPtg> opStack = new Stack <AbstractPtg>(stack);
                if (opStack.Count == 0)
                {
                    throw new Exception();
                }

                while (opStack.Count != 0)
                {
                    AbstractPtg ptg = opStack.Pop();

                    if (ptg is PtgAttrSum)
                    {
                        string     buffer = "";
                        PtgAttrSum ptgref = (PtgAttrSum)ptg;
                        buffer = ptg.getData() + "(" + resultStack.Pop() + ")";
                        resultStack.Push(buffer);
                    }
                    else if (ptg is PtgAttrIf || ptg is PtgAttrGoto || ptg is PtgAttrSemi ||
                             ptg is PtgAttrChoose || ptg is PtgAttrSpace)
                    {
                    }
                    else
                    {
                        switch (ptg.Id)
                        {
                        case PtgNumber.PtgInt:
                        case PtgNumber.PtgNum:
                        case PtgNumber.PtgBool:
                        case PtgNumber.PtgMissArg:
                        case PtgNumber.PtgErr:
                        {
                            resultStack.Push(ptg.getData());
                        }
                        break;

                        case PtgNumber.PtgRef:
                        {
                            PtgRef ptgref = (PtgRef)ptg;

                            int realCol = ptgref.col;
                            int realRw  = ptgref.rw + 1;

                            if (ptgref.colRelative)
                            {
                                realCol += col;
                            }

                            if (ptgref.rwRelative)
                            {
                                realRw += rw;
                            }

                            resultStack.Push(ExcelHelperClass.intToABCString(realCol, (realRw).ToString(), ptgref.colRelative, ptgref.rwRelative));
                        }
                        break;

                        case PtgNumber.PtgRefN:
                        {
                            PtgRefN ptgrefn = (PtgRefN)ptg;
                            int     realCol = (int)ptgrefn.col;
                            int     realRw;

                            if (ptgrefn.colRelative)
                            {
                                realCol += col;
                            }
                            if (realCol >= 0xFF)
                            {
                                realCol -= 0x0100;
                            }

                            if (ptgrefn.rwRelative)
                            {
                                realRw  = (Int16)ptgrefn.rw + 1;
                                realRw += rw;
                            }
                            else
                            {
                                realRw = ptgrefn.rw + 1;
                            }

                            resultStack.Push(ExcelHelperClass.intToABCString(realCol, (realRw).ToString(), ptgrefn.colRelative, ptgrefn.rwRelative));
                        }
                        break;

                        case PtgNumber.PtgUplus:
                        case PtgNumber.PtgUminus:
                        {
                            string buffer = "";
                            if (ptg.PopSize() > resultStack.Count)
                            {
                                throw new ExtractorException(ExtractorException.PARSEDFORMULAEXCEPTION);
                            }
                            buffer = ptg.getData() + resultStack.Pop();

                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgParen:
                        {
                            string buffer = "";
                            if (ptg.PopSize() > resultStack.Count)
                            {
                                throw new ExtractorException(ExtractorException.PARSEDFORMULAEXCEPTION);
                            }
                            buffer = "(" + resultStack.Pop() + ")";

                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgPercent:
                        {
                            string buffer = "";
                            if (ptg.PopSize() > resultStack.Count)
                            {
                                throw new ExtractorException(ExtractorException.PARSEDFORMULAEXCEPTION);
                            }
                            buffer = resultStack.Pop() + ptg.getData();

                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgAdd:
                        case PtgNumber.PtgDiv:
                        case PtgNumber.PtgMul:
                        case PtgNumber.PtgSub:
                        case PtgNumber.PtgPower:
                        case PtgNumber.PtgGt:
                        case PtgNumber.PtgGe:
                        case PtgNumber.PtgLt:
                        case PtgNumber.PtgLe:
                        case PtgNumber.PtgEq:
                        case PtgNumber.PtgNe:
                        case PtgNumber.PtgConcat:
                        case PtgNumber.PtgUnion:
                        case PtgNumber.PtgIsect:
                        {
                            string buffer = "";
                            if (ptg.PopSize() > resultStack.Count)
                            {
                                throw new ExtractorException(ExtractorException.PARSEDFORMULAEXCEPTION);
                            }
                            buffer = ptg.getData() + resultStack.Pop();
                            buffer = resultStack.Pop() + buffer;
                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgStr:
                        {
                            resultStack.Push("\"" + ptg.getData() + "\"");
                        }
                        break;

                        case PtgNumber.PtgArea:
                        {
                            string  buffer  = "";
                            PtgArea ptgarea = (PtgArea)ptg;
                            buffer = ExcelHelperClass.intToABCString((int)ptgarea.colFirst, (ptgarea.rwFirst + 1).ToString(), ptgarea.colFirstRelative, ptgarea.rwFirstRelative);
                            buffer = buffer + ":" + ExcelHelperClass.intToABCString((int)ptgarea.colLast, (ptgarea.rwLast + 1).ToString(), ptgarea.colLastRelative, ptgarea.rwLastRelative);


                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgAreaN:
                        {
                            string   buffer   = "";
                            PtgAreaN ptgarean = (PtgAreaN)ptg;
                            int      realRwFirst;
                            int      realRwLast;
                            int      realColFirst = (int)ptgarean.colFirst;
                            int      realColLast  = (int)ptgarean.colLast;

                            if (ptgarean.colFirstRelative)
                            {
                                realColFirst += col;
                            }

                            if (realColFirst >= 0xFF)
                            {
                                realColFirst -= 0x0100;
                            }

                            if (ptgarean.colLastRelative)
                            {
                                realColLast += col;
                            }
                            if (realColLast >= 0xFF)
                            {
                                realColLast -= 0x0100;
                            }

                            if (ptgarean.rwFirstRelative)
                            {
                                realRwFirst  = (Int16)ptgarean.rwFirst + 1;
                                realRwFirst += rw;
                            }
                            else
                            {
                                realRwFirst = ptgarean.rwFirst + 1;
                            }
                            if (ptgarean.rwLastRelative)
                            {
                                realRwLast  = (Int16)ptgarean.rwLast + 1;
                                realRwLast += rw;
                            }
                            else
                            {
                                realRwLast = ptgarean.rwLast + 1;
                            }

                            buffer = ExcelHelperClass.intToABCString(realColFirst, (realRwFirst).ToString(), ptgarean.colFirstRelative, ptgarean.rwFirstRelative);
                            buffer = buffer + ":" + ExcelHelperClass.intToABCString(realColLast, (realRwLast).ToString(), ptgarean.colLastRelative, ptgarean.rwLastRelative);


                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgExp:
                        {
                            PtgExp ptgexp = (PtgExp)ptg;
                            Stack <AbstractPtg> newptgstack = ((WorkSheetData)xlsContext.CurrentSheet).getArrayData(ptgexp.rw, ptgexp.col);
                            resultStack.Push(FormulaInfixMapping.mapFormula(newptgstack, xlsContext));
                            ((WorkSheetData)xlsContext.CurrentSheet).setFormulaUsesArray(ptgexp.rw, ptgexp.col);
                        }
                        break;

                        case PtgNumber.PtgRef3d:
                        {
                            try
                            {
                                PtgRef3d ptgr3d    = (PtgRef3d)ptg;
                                string   refstring = ExcelHelperClass.EscapeFormulaString(xlsContext.XlsDoc.WorkBookData.getIXTIString(ptgr3d.ixti));
                                refstring = string.IsNullOrEmpty(refstring) ? "" : "'" + refstring + "'" + "!";

                                string cellref = ExcelHelperClass.intToABCString((int)ptgr3d.col, (ptgr3d.rw + 1).ToString(), ptgr3d.colRelative, ptgr3d.rwRelative);

                                resultStack.Push(refstring + cellref);
                            }
                            catch (Exception)
                            {
                                resultStack.Push("#REF!");
                            }
                        }
                        break;

                        case PtgNumber.PtgArea3d:
                        {
                            try
                            {
                                PtgArea3d ptga3d    = (PtgArea3d)ptg;
                                string    refstring = ExcelHelperClass.EscapeFormulaString(xlsContext.XlsDoc.WorkBookData.getIXTIString(ptga3d.ixti));
                                refstring = string.IsNullOrEmpty(refstring) ? "" : "'" + refstring + "'" + "!";
                                string buffer = "";
                                buffer = ExcelHelperClass.intToABCString((int)ptga3d.colFirst, (ptga3d.rwFirst + 1).ToString(), ptga3d.colFirstRelative, ptga3d.rwFirstRelative);
                                buffer = buffer + ":" + ExcelHelperClass.intToABCString((int)ptga3d.colLast, (ptga3d.rwLast + 1).ToString(), ptga3d.colLastRelative, ptga3d.rwLastRelative);

                                resultStack.Push(refstring + buffer);
                            }
                            catch (Exception)
                            {
                                resultStack.Push("#REF!");
                            }
                        }
                        break;

                        case PtgNumber.PtgNameX:
                        {
                            PtgNameX ptgnx    = (PtgNameX)ptg;
                            string   opstring = xlsContext.XlsDoc.WorkBookData.getExternNameByRef(ptgnx.ixti, ptgnx.nameindex);
                            resultStack.Push(opstring);
                        }
                        break;

                        case PtgNumber.PtgName:
                        {
                            PtgName ptgn     = (PtgName)ptg;
                            string  opstring = xlsContext.XlsDoc.WorkBookData.getDefinedNameByRef(ptgn.nameindex);
                            resultStack.Push(opstring);
                        }
                        break;

                        case PtgNumber.PtgRefErr:
                        {
                            PtgRefErr ptgreferr = (PtgRefErr)ptg;
                            resultStack.Push(ptgreferr.getData());
                        }
                        break;

                        case PtgNumber.PtgRefErr3d:
                        {
                            try
                            {
                                PtgRefErr3d ptgreferr3d = (PtgRefErr3d)ptg;

                                string refstring = ExcelHelperClass.EscapeFormulaString(xlsContext.XlsDoc.WorkBookData.getIXTIString(ptgreferr3d.ixti));
                                refstring = string.IsNullOrEmpty(refstring) ? "" : "'" + refstring + "'" + "!";
                                resultStack.Push(refstring + ptgreferr3d.getData());
                            }
                            catch (Exception)
                            {
                                resultStack.Push("#REF!");
                            }
                        }
                        break;

                        case PtgNumber.PtgAreaErr3d:
                        {
                            try
                            {
                                PtgAreaErr3d ptgareaerr3d = (PtgAreaErr3d)ptg;
                                string       refstring    = ExcelHelperClass.EscapeFormulaString(xlsContext.XlsDoc.WorkBookData.getIXTIString(ptgareaerr3d.ixti));
                                refstring = string.IsNullOrEmpty(refstring) ? "" : "'" + refstring + "'" + "!";
                                resultStack.Push(refstring + ptgareaerr3d.getData());
                            }
                            catch (Exception)
                            {
                                resultStack.Push("#REF!");
                            }
                        }
                        break;

                        case PtgNumber.PtgFunc:
                        {
                            PtgFunc    ptgf   = (PtgFunc)ptg;
                            FtabValues value  = (FtabValues)ptgf.tab;
                            string     buffer = value.ToString();
                            buffer.Replace("_", ".");

                            // no param
                            if (value == FtabValues.NA || value == FtabValues.PI ||
                                value == FtabValues.TRUE || value == FtabValues.FALSE ||
                                value == FtabValues.RAND || value == FtabValues.NOW ||
                                value == FtabValues.TODAY
                                )
                            {
                                buffer += "()";
                            }
                            // One param
                            else if (value == FtabValues.ISNA || value == FtabValues.ISERROR ||
                                     value == FtabValues.SIN || value == FtabValues.COS ||
                                     value == FtabValues.TAN || value == FtabValues.ATAN ||
                                     value == FtabValues.SQRT || value == FtabValues.EXP ||
                                     value == FtabValues.LN || value == FtabValues.LOG10 ||
                                     value == FtabValues.ABS || value == FtabValues.INT ||
                                     value == FtabValues.SIGN || value == FtabValues.LEN ||
                                     value == FtabValues.VALUE || value == FtabValues.NOT ||
                                     value == FtabValues.DAY || value == FtabValues.MONTH ||
                                     value == FtabValues.YEAR || value == FtabValues.HOUR ||
                                     value == FtabValues.MINUTE || value == FtabValues.SECOND ||
                                     value == FtabValues.AREAS || value == FtabValues.ROWS ||
                                     value == FtabValues.COLUMNS || value == FtabValues.TRANSPOSE ||
                                     value == FtabValues.TYPE || value == FtabValues.ASIN ||
                                     value == FtabValues.ACOS || value == FtabValues.ISREF ||
                                     value == FtabValues.CHAR || value == FtabValues.LOWER ||
                                     value == FtabValues.UPPER || value == FtabValues.PROPER ||
                                     value == FtabValues.TRIM || value == FtabValues.CODE ||
                                     value == FtabValues.ISERR || value == FtabValues.ISTEXT ||
                                     value == FtabValues.ISNUMBER || value == FtabValues.ISBLANK ||
                                     value == FtabValues.T || value == FtabValues.N ||
                                     value == FtabValues.DATEVALUE || value == FtabValues.TIMEVALUE ||
                                     value == FtabValues.CLEAN || value == FtabValues.MDETERM ||
                                     value == FtabValues.MINVERSE || value == FtabValues.FACT ||
                                     value == FtabValues.ISNONTEXT || value == FtabValues.ISLOGICAL ||
                                     value == FtabValues.LENB || value == FtabValues.DBCS ||
                                     value == FtabValues.SINH || value == FtabValues.COSH ||
                                     value == FtabValues.TANH || value == FtabValues.ASINH ||
                                     value == FtabValues.ACOSH || value == FtabValues.ATANH ||
                                     value == FtabValues.INFO || value == FtabValues.ERROR_TYPE ||
                                     value == FtabValues.GAMMALN || value == FtabValues.EVEN ||
                                     value == FtabValues.FISHER || value == FtabValues.FISHERINV ||
                                     value == FtabValues.NORMSDIST || value == FtabValues.NORMSINV ||
                                     value == FtabValues.ODD || value == FtabValues.RADIANS ||
                                     value == FtabValues.DEGREES || value == FtabValues.COUNTBLANK ||
                                     value == FtabValues.DATESTRING || value == FtabValues.PHONETIC
                                     )
                            {
                                buffer += "(" + resultStack.Pop() + ")";
                            }
                            // two params
                            else if (value == FtabValues.ROUND || value == FtabValues.REPT ||
                                     value == FtabValues.MOD || value == FtabValues.TEXT ||
                                     value == FtabValues.ATAN2 || value == FtabValues.EXACT ||
                                     value == FtabValues.MMULT || value == FtabValues.ROUNDUP ||
                                     value == FtabValues.ROUNDDOWN || value == FtabValues.FREQUENCY ||
                                     value == FtabValues.CHIDIST || value == FtabValues.CHIINV ||
                                     value == FtabValues.COMBIN || value == FtabValues.FLOOR ||
                                     value == FtabValues.CEILING || value == FtabValues.PERMUT ||
                                     value == FtabValues.SUMXMY2 || value == FtabValues.SUMX2MY2 ||
                                     value == FtabValues.SUMX2PY2 || value == FtabValues.CHITEST ||
                                     value == FtabValues.CORREL || value == FtabValues.COVAR ||
                                     value == FtabValues.FTEST || value == FtabValues.INTERCEPT ||
                                     value == FtabValues.PEARSON || value == FtabValues.RSQ ||
                                     value == FtabValues.STEYX || value == FtabValues.SLOPE ||
                                     value == FtabValues.LARGE || value == FtabValues.SMALL ||
                                     value == FtabValues.QUARTILE || value == FtabValues.PERCENTILE ||
                                     value == FtabValues.TRIMMEAN || value == FtabValues.TINV ||
                                     value == FtabValues.POWER || value == FtabValues.COUNTIF ||
                                     value == FtabValues.NUMBERSTRING


                                     )
                            {
                                buffer += "(";
                                string buffer2 = resultStack.Pop();
                                buffer2 = resultStack.Pop() + "," + buffer2;

                                buffer += buffer2 + ")";
                            }
                            // Three params
                            else if (value == FtabValues.MID || value == FtabValues.DCOUNT ||
                                     value == FtabValues.DSUM || value == FtabValues.DAVERAGE ||
                                     value == FtabValues.DMIN || value == FtabValues.DMAX ||
                                     value == FtabValues.DSTDEV || value == FtabValues.DVAR ||
                                     value == FtabValues.MIRR || value == FtabValues.DATE ||
                                     value == FtabValues.TIME || value == FtabValues.SLN ||
                                     value == FtabValues.DPRODUCT || value == FtabValues.DSTDEVP ||
                                     value == FtabValues.DVARP || value == FtabValues.DCOUNTA ||
                                     value == FtabValues.MIDB || value == FtabValues.DGET ||
                                     value == FtabValues.CONFIDENCE || value == FtabValues.CRITBINOM ||
                                     value == FtabValues.EXPONDIST || value == FtabValues.FDIST

                                     || value == FtabValues.FINV || value == FtabValues.GAMMAINV ||
                                     value == FtabValues.LOGNORMDIST || value == FtabValues.LOGINV ||
                                     value == FtabValues.NEGBINOMDIST || value == FtabValues.NORMINV ||
                                     value == FtabValues.STANDARDIZE || value == FtabValues.POISSON ||
                                     value == FtabValues.TDIST || value == FtabValues.FORECAST
                                     )
                            {
                                buffer += "(";
                                string buffer2 = resultStack.Pop();
                                buffer2 = resultStack.Pop() + "," + buffer2;
                                buffer2 = resultStack.Pop() + "," + buffer2;
                                buffer += buffer2 + ")";
                            }
                            // four params
                            else if (value == FtabValues.REPLACE || value == FtabValues.SYD ||
                                     value == FtabValues.REPLACEB || value == FtabValues.BINOMDIST ||
                                     value == FtabValues.GAMMADIST || value == FtabValues.HYPGEOMDIST ||
                                     value == FtabValues.NORMDIST || value == FtabValues.WEIBULL ||
                                     value == FtabValues.TTEST || value == FtabValues.ISPMT

                                     )
                            {
                                buffer += "(";
                                string buffer2 = resultStack.Pop();
                                buffer2 = resultStack.Pop() + "," + buffer2;
                                buffer2 = resultStack.Pop() + "," + buffer2;
                                buffer2 = resultStack.Pop() + "," + buffer2;
                                buffer += buffer2 + ")";
                            }
                            if ((int)value != 0xff)
                            {
                            }
                            resultStack.Push(buffer);
                        }
                        break;

                        case PtgNumber.PtgFuncVar:
                        {
                            PtgFuncVar ptgfv = (PtgFuncVar)ptg;
                            // is Ftab or Cetab
                            if (!ptgfv.fCelFunc)
                            {
                                FtabValues value  = (FtabValues)ptgfv.tab;
                                string     buffer = value.ToString();
                                buffer.Replace("_", ".");
                                // 1 to x parameter
                                if (value == FtabValues.COUNT || value == FtabValues.IF ||
                                    value == FtabValues.ISNA || value == FtabValues.ISERROR ||
                                    value == FtabValues.AVERAGE || value == FtabValues.MAX ||
                                    value == FtabValues.MIN || value == FtabValues.SUM ||
                                    value == FtabValues.ROW || value == FtabValues.COLUMN ||
                                    value == FtabValues.NPV || value == FtabValues.STDEV ||
                                    value == FtabValues.DOLLAR || value == FtabValues.FIXED ||
                                    value == FtabValues.SIN || value == FtabValues.COS ||
                                    value == FtabValues.LOOKUP || value == FtabValues.INDEX ||
                                    value == FtabValues.AND || value == FtabValues.OR ||
                                    value == FtabValues.VAR || value == FtabValues.LINEST ||
                                    value == FtabValues.TREND || value == FtabValues.LOGEST ||
                                    value == FtabValues.GROWTH || value == FtabValues.PV ||
                                    value == FtabValues.FV || value == FtabValues.NPER ||
                                    value == FtabValues.PMT || value == FtabValues.RATE ||
                                    value == FtabValues.IRR || value == FtabValues.MATCH ||
                                    value == FtabValues.WEEKDAY || value == FtabValues.OFFSET ||
                                    value == FtabValues.ARGUMENT || value == FtabValues.SEARCH ||
                                    value == FtabValues.CHOOSE || value == FtabValues.HLOOKUP ||
                                    value == FtabValues.VLOOKUP || value == FtabValues.LOG ||
                                    value == FtabValues.LEFT || value == FtabValues.RIGHT ||
                                    value == FtabValues.SUBSTITUTE || value == FtabValues.FIND ||
                                    value == FtabValues.CELL || value == FtabValues.DDB ||
                                    value == FtabValues.INDIRECT || value == FtabValues.IPMT ||
                                    value == FtabValues.PPMT || value == FtabValues.COUNTA ||
                                    value == FtabValues.PRODUCT || value == FtabValues.STDEVP ||
                                    value == FtabValues.VARP || value == FtabValues.TRUNC ||
                                    value == FtabValues.USDOLLAR || value == FtabValues.FINDB ||
                                    value == FtabValues.SEARCHB || value == FtabValues.LEFTB ||
                                    value == FtabValues.RIGHTB || value == FtabValues.RANK ||
                                    value == FtabValues.ADDRESS || value == FtabValues.DAYS360 ||
                                    value == FtabValues.VDB || value == FtabValues.MEDIAN ||
                                    value == FtabValues.PRODUCT || value == FtabValues.DB ||
                                    value == FtabValues.AVEDEV || value == FtabValues.BETADIST ||
                                    value == FtabValues.BETAINV || value == FtabValues.PROB ||
                                    value == FtabValues.DEVSQ || value == FtabValues.GEOMEAN ||
                                    value == FtabValues.HARMEAN || value == FtabValues.SUMSQ ||
                                    value == FtabValues.KURT || value == FtabValues.SKEW ||
                                    value == FtabValues.ZTEST || value == FtabValues.PERCENTRANK ||
                                    value == FtabValues.MODE || value == FtabValues.CONCATENATE ||
                                    value == FtabValues.SUBTOTAL || value == FtabValues.SUMIF ||
                                    value == FtabValues.ROMAN || value == FtabValues.GETPIVOTDATA ||
                                    value == FtabValues.HYPERLINK || value == FtabValues.AVERAGEA ||
                                    value == FtabValues.MAXA || value == FtabValues.MINA ||
                                    value == FtabValues.STDEVPA || value == FtabValues.VARPA ||
                                    value == FtabValues.STDEVA || value == FtabValues.VARA
                                    )
                                {
                                    buffer += "(";
                                    if (ptgfv.cparams > 0)
                                    {
                                        string buffer2 = resultStack.Pop();
                                        for (int i = 1; i < ptgfv.cparams; i++)
                                        {
                                            buffer2 = resultStack.Pop() + "," + buffer2;
                                        }
                                        buffer += buffer2 + ")";
                                    }
                                    resultStack.Push(buffer);
                                }
                                else if ((int)value == 0xFF)
                                {
                                    buffer = "(";
                                    string buffer2 = resultStack.Pop();
                                    for (int i = 1; i < ptgfv.cparams - 1; i++)
                                    {
                                        buffer2 = resultStack.Pop() + "," + buffer2;
                                    }
                                    buffer += buffer2 + ")";
                                    // take the additional Operator from the Operandstack
                                    buffer = resultStack.Pop() + buffer;
                                    resultStack.Push(buffer);
                                }
                            }
                        }
                        break;

                        case PtgNumber.PtgMemFunc:
                        {
                            string value = FormulaInfixMapping.mapFormula(((PtgMemFunc)ptg).ptgStack, xlsContext);
                            resultStack.Push(value);
                        }
                        break;

                        case PtgNumber.PtgArray:
                        {
                            PtgExtraArray ptgExtraArray = ((PtgArray)ptg).ptgExtraArray;
                            StringBuilder builder       = new StringBuilder();
                            builder.Append("{");

                            string last = null;

                            foreach (SerAr item in ptgExtraArray.array)
                            {
                                if (last != null)
                                {
                                    builder.Append(last);
                                    builder.Append(";");
                                }

                                last = item.ToString();
                            }
                            if (last != null)
                            {
                                builder.Append(last);
                            }
                            builder.Append("}");

                            resultStack.Push(builder.ToString());
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceLogger.DebugInternal(ex.Message.ToString());
                resultStack.Push("");
            }
            if (resultStack.Count == 0)
            {
                resultStack.Push("");
            }

            return(resultStack.Pop());
        }