Ejemplo n.º 1
0
        internal static string AsString(TParsedTokenList Tokens, int CellRow, int CellCol,
                                        ICellList CellList, TWorkbookGlobals Globals, int MaxStringConstantLen, bool WritingXlsx, bool SkipEqual)
        {
            string        StartFormula = fts(TFormulaToken.fmStartFormula); //Formulas do not always begin with "=". Array formulas begin with "{", and they override this var to empty.
            TFormulaStack ParsedStack  = new TFormulaStack();

            bool R1C1 = false;

            if (Globals != null && !WritingXlsx)
            {
                R1C1 = Globals.Workbook.FormulaReferenceStyle == TReferenceStyle.R1C1;
            }

            Tokens.ResetPositionToStart();
            while (!Tokens.Eof())
            {
                TBaseParsedToken Token = Tokens.ForwardPop();
                ptg BaseToken          = Token.GetBaseId;
                Evaluate(Token, R1C1, CellRow, CellCol, BaseToken, Tokens, CellList, Globals, ParsedStack, ref StartFormula, MaxStringConstantLen, WritingXlsx);
            }             //while


            if (WritingXlsx || SkipEqual)
            {
                StartFormula = String.Empty;
            }

            if (ParsedStack.Count == 0)
            {
                return(String.Empty);                         //StartFormula + TFormulaMessages.ErrString(TFlxFormulaErrorValue.ErrRef);  This is needed for deleted named ranges.
            }
            return(StartFormula + ParsedStack.Pop());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// FmlaWithoutArrayLen might be less than the total array len
        /// </summary>
        internal static byte[] GetTokenData(TNameRecordList Names, TParsedTokenList Tokens, TFormulaType FmlaType, out int FmlaLenWithoutArray)
        {
            // Remember to ungrow maxrow and maxcol from 2007 too biff8
            // Tokens that grow are ptgref, area, 3dref and 3darea. All of them (and nothing else) should ungrow.

            using (MemoryStream Data = new MemoryStream())
            {
                using (MemoryStream ArrayData = new MemoryStream())
                {
                    int[]        TokenOffset = new int[Tokens.Count + 1];
                    TTokenOffset StreamPos   = new TTokenOffset();
                    Int32List    FuturePos   = new Int32List();

                    Tokens.ResetPositionToStart();
                    while (!Tokens.Eof())
                    {
                        TBaseParsedToken Token = Tokens.ForwardPop();
                        TokenOffset[Tokens.SavePosition()] = (int)Data.Position;
                        ptg BaseToken = Token.GetBaseId;
                        Add(Data, ArrayData, Token, BaseToken, Tokens, StreamPos, FmlaType, FuturePos);
                    } //while

                    TokenOffset[Tokens.Count] = (int)Data.Position;
                    FixFutureFunctions(Names, FuturePos, Tokens, Data, TokenOffset, ref StreamPos);
                    FixGotoAndMemTokens(Tokens, Data, TokenOffset, StreamPos);
                    ArrayData.Position  = 0;
                    Data.Position       = Data.Length;               //FixGoto will change this.
                    FmlaLenWithoutArray = (int)Data.Length;
                    ArrayData.WriteTo(Data);
                    return(Data.ToArray());
                }
            }
        }
Ejemplo n.º 3
0
        static TToken[] Convert(TParsedTokenList Tokens)
        {
            TToken[] Result = new TToken[Tokens.Count];
            Tokens.ResetPositionToStart();
            int i = 0;

            while (!Tokens.Eof())
            {
                TBaseParsedToken tk = Tokens.ForwardPop();
                Result[i] = GetPublicToken(tk);
                i++;
            }

            return(Result);
        }
Ejemplo n.º 4
0
        internal void Go(TParsedTokenList Data, bool RefIsInInsertingSheet)
        {
            Data.ResetPositionToStart();
            while (!Data.Eof())
            {
                TBaseParsedToken r = Data.ForwardPop();
                ptg id             = r.GetBaseId;
                switch (id)
                {
                case ptg.Exp:
                    DoArrayFmla((TExp_Token)r);
                    break;

                case ptg.Tbl:
                    TTableToken tbl = r as TTableToken;
                    if (tbl != null)     //might be also TTableObjToken
                    {
                        DoTable(tbl);
                    }
                    break;

                case ptg.Name:
                    DoName((TNameToken)r);
                    break;

                case ptg.RefErr:
                case ptg.Ref:
                case ptg.RefN:
                    DoRef((TRefToken)r, RefIsInInsertingSheet);
                    break;

                case ptg.AreaErr:
                case ptg.Area:
                case ptg.AreaN:
                    DoArea((TAreaToken)r, RefIsInInsertingSheet);
                    break;

                case ptg.MemArea:
                    DoMemArea(Data, (TMemAreaToken)r, RefIsInInsertingSheet);
                    break;

                case ptg.NameX:
                {
                    //We'll do Do3d only for local names.
                    //bool ThisRefIsInInsertingSheet;
                    //Do3D(r, out ThisRefIsInInsertingSheet);
                    DoNameX((TNameXToken)r);
                }
                break;

                case ptg.Ref3d:
                case ptg.Ref3dErr:
                {
                    bool ThisRefIsInInsertingSheet;
                    Do3D(r, out ThisRefIsInInsertingSheet);
                    DoRef((TRef3dToken)r, ThisRefIsInInsertingSheet);
                    break;
                }

                case ptg.Area3dErr:
                case ptg.Area3d:
                {
                    bool ThisRefIsInInsertingSheet;
                    Do3D(r, out ThisRefIsInInsertingSheet);
                    DoArea((TArea3dToken)r, ThisRefIsInInsertingSheet);
                }
                break;
                }
            }
        }