Beispiel #1
0
        private static byte[] ConvertToBiff8(TExternSheetList ExternSheetList, byte Token, byte[] Data, ref int tPos)
        {
            byte[] Result;
            int    rPos = 0;

            switch (TBaseParsedToken.CalcBaseToken((ptg)Token))
            {
            case ptg.Name:
                Result = new byte[4];      //Wrong on Excel docs!
                BitOps.SetWord(Result, 0, BitOps.GetWord(Data, tPos));
                tPos += 14;
                return(Result);

            case ptg.NameX:
                Result = new byte[6];     //This is actually 6
                BitOps.SetWord(Result, 2, BitOps.GetWord(Data, tPos + 10));
                tPos += 24;
                return(Result);

            case ptg.Ref:
            case ptg.RefN:
                Result = new byte[4];
                ConvertRowsAndColumns7To8(Data, Result, ref tPos, ref rPos, false);
                return(Result);

            case ptg.Area:
            case ptg.AreaN:
                Result = new byte[8];
                ConvertRowsAndColumns7To8(Data, Result, ref tPos, ref rPos, true);
                return(Result);

            case ptg.RefErr:
                tPos += 3;
                return(new byte[4]);

            case ptg.AreaErr:
                tPos += 6;
                return(new byte[8]);

            case ptg.Ref3d:
            case ptg.Ref3dErr:
                Result = new byte[6];
                Convert3D7To8(ExternSheetList, Token, Data, Result, ref tPos, ref rPos);
                ConvertRowsAndColumns7To8(Data, Result, ref tPos, ref rPos, false);
                return(Result);

            case ptg.Area3d:
            case ptg.Area3dErr:
                Result = new byte[10];
                Convert3D7To8(ExternSheetList, Token, Data, Result, ref tPos, ref rPos);
                ConvertRowsAndColumns7To8(Data, Result, ref tPos, ref rPos, true);
                return(Result);
            }

            XlsMessages.ThrowException(XlsErr.ErrBadToken, Token);
            return(null);  //just to compile.
        }
Beispiel #2
0
        internal void LoadBiff7(byte[] Data, int Pos, TExternSheetList ExternSheetList, TPxlVersion PxlVersion)
        {
            TFormulaErrorValue Err = Load(Data, Pos, TFmlaConvert.Biff7To8, PxlVersion, ExternSheetList, null); //No references to load Biff7

            if (Err != null)
            {
                XlsMessages.ThrowException(XlsErr.ErrBadToken, Err.Token);
            }
        }
Beispiel #3
0
        private byte[] ReadBiff7Formula(TExternSheetList ExternSheetList, Stream aDataStream, byte[] Data, int DataPos, int LenPos)
        {
            ShRead(aDataStream, Data, DataPos, Data.Length - DataPos);
            TBiff7FormulaConverter ResultList = new TBiff7FormulaConverter();

            ResultList.LoadBiff7(Data, DataPos, ExternSheetList, PxlVersion);

            int ResultSize = ResultList.Size;

            byte[] Result = new byte[DataPos + ResultSize];
            Array.Copy(Data, 0, Result, 0, DataPos);
            ResultList.CopyToPtr(Result, DataPos);
            BitOps.SetWord(Result, LenPos, ResultSize);
            return(Result);
        }
Beispiel #4
0
        internal TPxlRecordLoader(Stream aDataStream, TExternSheetList aExternSheetList,
                                  TEncryptionData aEncryption, TSST aSST, IFlexCelFontList aFontList, TBorderList aBorderList,
                                  TPatternList aPatternList, ExcelFile aWorkbook, TBiff8XFMap aXFMap, int aMainBookXFCount, TNameRecordList aNames, TVirtualReader VirtualReader)
            : base(aSST, aFontList, aEncryption, aWorkbook.XlsBiffVersion, aXFMap, aNames, VirtualReader)
        {
            DataStream         = aDataStream;
            FExternSheetList   = aExternSheetList;
            FormatId           = 233;
            FWorkbook          = aWorkbook;
            BorderList         = aBorderList;
            PatternList        = aPatternList;
            DataStreamLength   = DataStream.Length;
            DataStreamPosition = DataStream.Position;  //cached for performance.

            MainBookXFCount = aMainBookXFCount;
        }
Beispiel #5
0
        private static void Convert3D7To8(TExternSheetList ExternSheetList, byte Token, byte[] Data, byte[] Result, ref int tPos, ref int rPos)
        {
            unchecked
            {
                Int16 ex = (Int16)BitOps.GetWord(Data, tPos);
                if (ex >= 0)
                {
                    XlsMessages.ThrowException(XlsErr.ErrBadToken, Token);
                }
            }

            tPos += 10;

            BitOps.SetWord(Result, rPos, ExternSheetList.AddExternSheet(BitOps.GetWord(Data, tPos), BitOps.GetWord(Data, tPos + 2)));
            tPos += 4;
            rPos += 2;
        }
Beispiel #6
0
        private TFormulaErrorValue Load(byte[] Data, int Pos, TFmlaConvert ConvertType, TPxlVersion PxlVersion, TExternSheetList ExternSheetList, TReferences References)
        {
            int tPos = Pos;
            int bPos = Pos;
            int fPos = Data.Length;

            while (tPos < fPos)
            {
                byte Token = Data[tPos];
                if (Token >= 0x3 && Token <= 0x16)
                {
                    tPos++;                               //XlsTokens.IsUnaryOp(Token)||XlsTokens.IsBinaryOp(Token) || Token==XlsTokens.tk_MissArg ;
                }
                else
                if (XlsTokens.Is_tk_Operand(Token))
                {
                    tPos++;
                    Flush(Data, ref bPos, tPos);
                    if (ConvertType == TFmlaConvert.Biff7To8)
                    {
                        ParsedTokens.Add(ConvertToBiff8(ExternSheetList, Token, Data, ref tPos));
                    }
                    else
                    {
                        byte[] ConvertedData = ConvertToBiff7(References, Token, Data, ref tPos);
                        if (ConvertedData == null)
                        {
                            return(new TFormulaErrorValue(Token));
                        }
                        ParsedTokens.Add(ConvertedData);
                    }
                    bPos = tPos;
                }
                else
                {
                    switch (Token)
                    {
                    case XlsTokens.tk_Str:
                        if (PxlVersion == TPxlVersion.v10)
                        {
                            tPos++;
                            Flush(Data, ref bPos, tPos);

                            byte[] StrValue = new byte[Data[tPos] + 2];
                            StrValue[0] = Data[tPos]; //String len.
                            StrValue[1] = 0;          //Not wide string.
                            Array.Copy(Data, tPos + 1, StrValue, 2, StrValue.Length - 2);
                            ParsedTokens.Add(StrValue);
                            tPos += Data[tPos] + 1;
                            bPos  = tPos;
                        }
                        else
                        {
                            tPos += 1 + (int)StrOps.GetStrLen(false, Data, tPos + 1, false, 0);
                        }
                        break;

                    case XlsTokens.tk_Err:
                    case XlsTokens.tk_Bool:
                        tPos += 1 + 1;
                        break;

                    case XlsTokens.tk_Int:
                    case 0x21:          //XlsTokens.Is_tk_Func(Token):
                    case 0x41:
                    case 0x61:
                        tPos += 1 + 2;
                        break;

                    case 0x22:         //XlsTokens.Is_tk_FuncVar(Token):
                    case 0x42:
                    case 0x62:
                        tPos += 1 + 3;
                        break;

                    case XlsTokens.tk_Num:
                        tPos += 1 + 8;
                        break;

                    case XlsTokens.tk_Attr:
                        bool IgnoreAttr = false;
                        if ((Data[tPos + 1] & (0x2 | 0x4 | 0x8)) != 0)         //optimized if, goto, optimized chose.
                        {
                            Flush(Data, ref bPos, tPos);
                            IgnoreAttr = true;
                        }

                        if ((Data[tPos + 1] & 0x04) == 0x04)
                        {
                            tPos += (BitOps.GetWord(Data, tPos + 2) + 1) * 2;
                        }
                        tPos += 1 + 3;

                        if (IgnoreAttr)
                        {
                            bPos = tPos;         //ignore the attribute, as it contains offsets to the formula that will change.
                        }
                        break;

                    case XlsTokens.tk_Table:
                        return(new TFormulaErrorValue(Token));

                    case XlsTokens.tk_MemFunc:
                    case XlsTokens.tk_MemFunc + 0x20:
                    case XlsTokens.tk_MemFunc + 0x40:
                        tPos += 1 + 2;         //+ GetWord(Data, tPos+1);
                        break;

                    case XlsTokens.tk_MemArea:
                    case XlsTokens.tk_MemArea + 0x20:
                    case XlsTokens.tk_MemArea + 0x40:
                    case XlsTokens.tk_MemErr:
                    case XlsTokens.tk_MemErr + 0x20:
                    case XlsTokens.tk_MemErr + 0x40:
                    case XlsTokens.tk_MemNoMem:
                    case XlsTokens.tk_MemNoMem + 0x20:
                    case XlsTokens.tk_MemNoMem + 0x40:
                        tPos += 1 + 6;         //+ GetWord(Data, tPos+1);
                        break;

                    default:
                        return(new TFormulaErrorValue(Token));
                    }
                }
            }//while
            Flush(Data, ref bPos, tPos);
            return(null);
        }