Esempio n. 1
0
        protected override void DoArea(TAreaToken areat, bool RefIsInInsertingSheet)
        {
            int r1 = areat.Row1;
            int r2 = areat.Row2;
            int c1 = areat.Col1;
            int c2 = areat.Col2;

            if (RefIsInInsertingSheet)
            {
                TXlsCellRange NewRange = CellRange.Offset(NewRow, NewCol);

                bool RowRel1 = areat.CanHaveRelativeOffsets && !areat.RowAbs1;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColRel1 = areat.CanHaveRelativeOffsets && !areat.ColAbs1;
                bool RowRel2 = areat.CanHaveRelativeOffsets && !areat.RowAbs2;
                bool ColRel2 = areat.CanHaveRelativeOffsets && !areat.ColAbs2;

                if (RowRel1)
                {
                    r1 = TBaseRefToken.WrapRow(FmlaRow + r1, false);
                }
                if (ColRel1)
                {
                    c1 = TBaseRefToken.WrapColumn(FmlaCol + c1, false);
                }
                if (RowRel2)
                {
                    r2 = TBaseRefToken.WrapRow(FmlaRow + r2, false);
                }
                if (ColRel2)
                {
                    c2 = TBaseRefToken.WrapColumn(FmlaCol + c2, false);
                }

                bool RefInside  = CellRange.HasRow(r1) && CellRange.HasCol(c1) && CellRange.HasRow(r2) && CellRange.HasCol(c2);
                bool FmlaInside = CellRange.HasRow(FmlaRow) && CellRange.HasCol(FmlaCol);

                //only if the ref was *not* on the original range.
                if (!RefInside && NewRange.HasRow(r1) && NewRange.HasCol(c1) && NewRange.HasRow(r2) && NewRange.HasCol(c2))
                {
                    areat.CreateInvalidRef();
                }
                else
                {
                    r1 = MoveRef(areat, ref areat.Row1, r1, 0, NewRow - CellRange.Top, FmlaRow, RowRel1, RefInside, FmlaInside, FlxConsts.Max_Rows, false);
                    c1 = MoveRef(areat, ref areat.Col1, c1, 0, NewCol - CellRange.Left, FmlaCol, ColRel1, RefInside, FmlaInside, FlxConsts.Max_Columns, false);
                    r2 = MoveRef(areat, ref areat.Row2, r2, 0, NewRow - CellRange.Top, FmlaRow, RowRel2, RefInside, FmlaInside, FlxConsts.Max_Rows, false);
                    c2 = MoveRef(areat, ref areat.Col2, c2, 0, NewCol - CellRange.Left, FmlaCol, ColRel2, RefInside, FmlaInside, FlxConsts.Max_Columns, false);
                }
            }
            if (Bounds != null)
            {
                Bounds.AddRow(r1);
                Bounds.AddRow(r2);
                Bounds.AddCol(c1);
                Bounds.AddCol(c2);
            }
        }
Esempio n. 2
0
        private static string GetArea(bool R1C1, TAreaToken Area, int CellRow, int CellCol)
        {
            int Row1 = Area.GetRow1(CellRow) + 1;
            int Row2 = Area.GetRow2(CellRow) + 1;
            int Col1 = Area.GetCol1(CellCol) + 1;
            int Col2 = Area.GetCol2(CellCol) + 1;

            if (Col1 == 1 && Col2 == FlxConsts.Max_Columns + 1)
            {
                return(GetRowRange(R1C1, Row1, Row2, CellRow, Area.RowAbs1, Area.RowAbs2));
            }
            if (Row1 == 1 && Row2 == FlxConsts.Max_Rows + 1)
            {
                return(GetColRange(R1C1, Col1, Col2, CellCol, Area.ColAbs1, Area.ColAbs2));
            }

            return(Get1Ref(R1C1, Row1, Col1, CellRow, CellCol, Area.RowAbs1, Area.ColAbs1) + fts(TFormulaToken.fmRangeSep)
                   + Get1Ref(R1C1, Row2, Col2, CellRow, CellCol, Area.RowAbs2, Area.ColAbs2));
        }
Esempio n. 3
0
        private static void Add(Stream Data, Stream ArrayData, TBaseParsedToken Token, ptg BaseToken, TParsedTokenList Tokens, TTokenOffset StreamPos, TFormulaType FmlaType, Int32List FuturePos)
        {
            if (IsError(BaseToken, FmlaType))
            {
                Data.WriteByte(0x1C); //PtgErr
                Data.WriteByte(0x2A);
                return;
            }


            Data.WriteByte((byte)Token.GetId);
            switch (BaseToken)
            {
            case ptg.Exp:
                TExp_Token exp = (TExp_Token)Token;
                Biff8Utils.CheckRow(exp.Row);
                Biff8Utils.CheckCol(exp.Col);
                WriteWord(Data, exp.Row);
                WriteWord(Data, exp.Col);
                break;

            case ptg.Tbl:
                TTableObjToken tblo = Token as TTableObjToken;
                if (tblo != null)
                {
                    //no biff8 checks here. This numbers might be anything.
                    WriteWord(Data, tblo.Row);
                    WriteWord(Data, tblo.Col);
                }
                else
                {
                    TTableToken tbl = (TTableToken)Token;
                    Biff8Utils.CheckRow(tbl.Row);
                    Biff8Utils.CheckCol(tbl.Col);
                    WriteWord(Data, tbl.Row);
                    WriteWord(Data, tbl.Col);
                }
                break;

            case ptg.Add:
            case ptg.Sub:
            case ptg.Mul:
            case ptg.Div:
            case ptg.Power:
            case ptg.Concat:
            case ptg.LT:
            case ptg.LE:
            case ptg.EQ:
            case ptg.GE:
            case ptg.GT:
            case ptg.NE:
            case ptg.Isect:
            case ptg.Union:
            case ptg.Range:
            case ptg.Uplus:
            case ptg.Uminus:
            case ptg.Percent:
            case ptg.Paren:
            case ptg.MissArg:
                break;


            case ptg.Str:
            {
                TStrDataToken tkd = Token as TStrDataToken;
                string        s   = tkd.GetData();
                if (s.Length > FlxConsts.Max_FormulaStringConstant)
                {
                    FlxMessages.ThrowException(FlxErr.ErrStringConstantInFormulaTooLong, s, String.Empty);
                }
                TExcelString Xs = new TExcelString(TStrLenLength.is8bits, s, null, false);
                byte[]       b  = new byte[Xs.TotalSize()];
                Xs.CopyToPtr(b, 0);
                Data.Write(b, 0, b.Length);
                break;
            }

            case ptg.Attr:
                WriteAttr(Data, Token, StreamPos, Tokens.SavePosition());

                break;

            /*
             * case ptg.Sheet: //Can't happen, ConvertBiff8ToInternal skips them.
             * case ptg.EndSheet: //Can't happen, ConvertBiff8ToInternal skips them.
             *  break;*/

            case ptg.Err:
            {
                Data.WriteByte((byte)((TErrDataToken)Token).GetData());
                break;
            }

            case ptg.Bool:
            {
                if (((TBoolDataToken)Token).GetData())
                {
                    Data.WriteByte(1);
                }
                else
                {
                    Data.WriteByte(0);
                }
                break;
            }

            case ptg.Int:
            {
                UInt16 a = (UInt16)((TIntDataToken)Token).GetData();
                WriteWord(Data, a);
                break;
            }

            case ptg.Num:
            {
                double d = ((TNumDataToken)Token).GetData();
                Data.Write(BitConverter.GetBytes(d), 0, 8);
                break;
            }


            case ptg.Array:
            {
                Data.Write(new byte[7], 0, 7);
                TArrayDataToken tk = (TArrayDataToken)Token;
                object[,] Arr = tk.GetData;

                int ColCount = Arr.GetLength(1) - 1;
                if (ColCount < 0 || ColCount > FlxConsts.Max_Columns97_2003)
                {
                    FlxMessages.ThrowException(FlxErr.ErrInvalidCols, ColCount, FlxConsts.Max_Columns97_2003 + 1);
                }
                ArrayData.WriteByte((byte)(ColCount));

                int RowCount = Arr.GetLength(0) - 1;
                if (RowCount < 0 || RowCount > FlxConsts.Max_Rows)
                {
                    FlxMessages.ThrowException(FlxErr.ErrInvalidRows, RowCount, FlxConsts.Max_Rows + 1);
                }
                WriteWord(ArrayData, RowCount);

                for (int r = 0; r <= RowCount; r++)
                {
                    for (int c = 0; c <= ColCount; c++)
                    {
                        WriteArrayObject(ArrayData, Arr[r, c]);
                    }
                }

                break;
            }

            case ptg.Func:
            {
                TBaseFunctionToken ft = (TBaseFunctionToken)Token;
                TCellFunctionData  fd = ft.GetFunctionData();
                WriteWord(Data, fd.Index);
                break;
            }

            case ptg.FuncVar:
            {
                TBaseFunctionToken ft = (TBaseFunctionToken)Token;
                TCellFunctionData  fd = ft.GetFunctionData();
                if (!BackFromFutureToUserDef(Data, Tokens, FuturePos, ft, fd))
                {
                    Data.WriteByte((byte)ft.ArgumentCount);
                    WriteWord(Data, fd.Index);
                }
                break;
            }

            case ptg.Name:
                WriteWord(Data, ((TNameToken)Token).NameIndex);
                WriteWord(Data, 0);
                break;

            case ptg.Ref:
            case ptg.RefN:
            case ptg.RefErr:
            {
                TRefToken reft = (TRefToken)Token;
                WriteRef(Data, reft.CanHaveRelativeOffsets, reft.Row, reft.RowAbs, reft.Col, reft.ColAbs);
                break;
            }

            case ptg.Area:
            case ptg.AreaN:
            case ptg.AreaErr:
            {
                TAreaToken areat = (TAreaToken)Token;
                WriteArea(Data, areat.CanHaveRelativeOffsets, areat.Row1, areat.RowAbs1, areat.Col1, areat.ColAbs1, areat.Row2, areat.RowAbs2, areat.Col2, areat.ColAbs2);
                break;
            }

            case ptg.MemArea:
            {
                WriteWord(Data, 0);
                WriteWord(Data, 0);
                StreamPos.Add((int)Data.Position, Tokens.SavePosition());
                WriteWord(Data, 0);

                TRefRange[] Range = ((TMemAreaToken)Token).Data;
                WriteWord(ArrayData, Range.Length);
                foreach (TRefRange OneRef in Range)
                {
                    int r1 = Biff8Utils.CheckAndContractBiff8Row(OneRef.FirstRow);
                    int r2 = Biff8Utils.CheckAndContractBiff8Row(OneRef.LastRow);
                    int c1 = Biff8Utils.CheckAndContractBiff8Col(OneRef.FirstCol);
                    int c2 = Biff8Utils.CheckAndContractBiff8Col(OneRef.LastCol);

                    WriteWord(ArrayData, r1);
                    WriteWord(ArrayData, r2);
                    WriteWord(ArrayData, c1);
                    WriteWord(ArrayData, c2);
                }

                break;
            }

            case ptg.MemErr:
            case ptg.MemNoMem:
                WriteWord(Data, 0);
                WriteWord(Data, 0);
                StreamPos.Add((int)Data.Position, Tokens.SavePosition());
                WriteWord(Data, 0);
                break;

            case ptg.MemFunc:
            case ptg.MemAreaN:
            case ptg.MemNoMemN:
                StreamPos.Add((int)Data.Position, Tokens.SavePosition());
                WriteWord(Data, 0);
                break;

            case ptg.NameX:
                TNameXToken NameX = (TNameXToken)Token;
                WriteWord(Data, NameX.FExternSheet);
                WriteWord(Data, NameX.NameIndex);
                WriteWord(Data, 0);
                break;

            case ptg.Ref3dErr:
            case ptg.Ref3d:
                TRef3dToken reft3d = (TRef3dToken)Token;
                WriteWord(Data, reft3d.FExternSheet);
                WriteRef(Data, reft3d.CanHaveRelativeOffsets, reft3d.Row, reft3d.RowAbs, reft3d.Col, reft3d.ColAbs);
                break;

            case ptg.Area3d:
            case ptg.Area3dErr:
                TArea3dToken areat3d = (TArea3dToken)Token;
                WriteWord(Data, areat3d.FExternSheet);
                WriteArea(Data, areat3d.CanHaveRelativeOffsets, areat3d.Row1, areat3d.RowAbs1, areat3d.Col1, areat3d.ColAbs1, areat3d.Row2, areat3d.RowAbs2, areat3d.Col2, areat3d.ColAbs2);
                break;

            default:
                XlsMessages.ThrowException(XlsErr.ErrInternal);                         //All tokens here should exist
                break;
            }
        }
Esempio n. 4
0
        protected override void DoArea(TAreaToken areat, bool RefIsInInsertingSheet)
        {
            int r1 = areat.Row1;
            int r2 = areat.Row2;
            int c1 = areat.Col1;
            int c2 = areat.Col2;

            if (RefIsInInsertingSheet)
            {
                bool RowRel1 = areat.CanHaveRelativeOffsets && !areat.RowAbs1;  //CanHaveRelativeOffsets is true for RefN tokens.
                bool ColRel1 = areat.CanHaveRelativeOffsets && !areat.ColAbs1;
                bool RowRel2 = areat.CanHaveRelativeOffsets && !areat.RowAbs2;
                bool ColRel2 = areat.CanHaveRelativeOffsets && !areat.ColAbs2;

                if (RowRel1)
                {
                    r1 = TBaseRefToken.WrapRow(FmlaRow + r1, false);
                }
                if (ColRel1)
                {
                    c1 = TBaseRefToken.WrapColumn(FmlaCol + c1, false);
                }
                if (RowRel2)
                {
                    r2 = TBaseRefToken.WrapRow(FmlaRow + r2, false);
                }
                if (ColRel2)
                {
                    c2 = TBaseRefToken.WrapColumn(FmlaCol + c2, false);
                }

                bool InColRange = CellRange.HasCol(c1) && CellRange.HasCol(c2);
                if (InColRange)
                {
                    if (RowCount < 0)
                    {
                        areat.DeleteRowsArea(FmlaRow, RowCount, CellRange);  //Handles the complexities of deleting ranges.
                    }
                }

                if (RowCount > 0)
                {
                    bool FmlaInsideDown = (FmlaRow >= CellRange.Top) && CellRange.HasCol(FmlaCol);
                    bool RefInsideDown1 = r1 >= CellRange.Top && InColRange;
                    bool RefInsideDown2 = r2 >= CellRange.Top && r2 != FlxConsts.Max_Rows && InColRange;
                    r1 = MoveRef(areat, ref areat.Row1, r1, CellRange.Top, RowCount * CellRange.RowCount, FmlaRow, RowRel1, RefInsideDown1, FmlaInsideDown, FlxConsts.Max_Rows, true);
                    r2 = MoveRef(areat, ref areat.Row2, r2, CellRange.Top, RowCount * CellRange.RowCount, FmlaRow, RowRel2, RefInsideDown2, FmlaInsideDown, FlxConsts.Max_Rows, true);
                }

                bool InRowRange = CellRange.HasRow(r1) && CellRange.HasRow(r2);
                if (InRowRange)
                {
                    if (ColCount < 0)
                    {
                        areat.DeleteColsArea(FmlaCol, ColCount, CellRange);  //Handles the complexities of deleting ranges.
                    }
                }

                if (ColCount > 0)
                {
                    bool FmlaInsideRight = (FmlaCol >= CellRange.Left) && CellRange.HasRow(FmlaRow);
                    bool RefInsideRight1 = c1 >= CellRange.Left && InRowRange;
                    bool RefInsideRight2 = c2 >= CellRange.Left && c2 != FlxConsts.Max_Columns && InRowRange;
                    c1 = MoveRef(areat, ref areat.Col1, c1, CellRange.Top, ColCount * CellRange.ColCount, FmlaCol, ColRel1, RefInsideRight1, FmlaInsideRight, FlxConsts.Max_Columns, true);
                    c2 = MoveRef(areat, ref areat.Col2, c2, CellRange.Top, ColCount * CellRange.ColCount, FmlaCol, ColRel2, RefInsideRight2, FmlaInsideRight, FlxConsts.Max_Columns, true);
                }
            }


            bool ForgetAbsolute1 = SemiAbsoluteMode && CellRange.HasRow(r1) && CellRange.HasCol(c1);
            bool ForgetAbsolute2 = SemiAbsoluteMode && CellRange.HasRow(r2) && CellRange.HasCol(c2);

            OffsetCopy(areat, ref areat.Row1, CopyRowOffset, FlxConsts.Max_Rows, areat.RowAbs1, ForgetAbsolute1);
            OffsetCopy(areat, ref areat.Col1, CopyColOffset, FlxConsts.Max_Columns, areat.ColAbs1, ForgetAbsolute1);
            OffsetCopy(areat, ref areat.Row2, CopyRowOffset, FlxConsts.Max_Rows, areat.RowAbs2, ForgetAbsolute2);
            OffsetCopy(areat, ref areat.Col2, CopyColOffset, FlxConsts.Max_Columns, areat.ColAbs2, ForgetAbsolute2);

            if (Bounds != null)
            {
                Bounds.AddRow(areat.Row1);
                Bounds.AddRow(areat.Row2);
                Bounds.AddCol(areat.Col1);
                Bounds.AddCol(areat.Col2);
            }
        }
Esempio n. 5
0
 protected abstract void DoArea(TAreaToken areat, bool RefIsInInsertingSheet);