Exemplo n.º 1
0
 void Execute(Excel excel)
 {
     CellRange[] oldSelection = (_workSheet.Selections != null) ? Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_workSheet.Selections) : null;
     if (_dragFillExtent.AutoFillType == AutoFillType.ClearValues)
     {
         ExecuteDragFillClear(excel);
     }
     else
     {
         ExecuteDragFill(excel);
     }
     if (((_savedFilledViewportCells != null) && _savedFilledViewportCells.IsValueSaved()) && object.ReferenceEquals(excel.ActiveSheet, _workSheet))
     {
         CellRange fillRange = _dragFillExtent.FillRange;
         CopyMoveHelper.RaiseValueChanged(excel, fillRange.Row, fillRange.Column, fillRange.RowCount, fillRange.ColumnCount, _savedFilledViewportCells.GetValues());
     }
     CellRange[] newSelection = (_workSheet.Selections != null) ? Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_workSheet.Selections) : null;
     if (excel.RaiseSelectionChanging(oldSelection, newSelection))
     {
         excel.RaiseSelectionChanged();
     }
 }
Exemplo n.º 2
0
        bool Undo(Excel excel)
        {
            bool flag = UndoSetArrayFormula(excel);

            CellRange[]     oldSelection = (_workSheet.Selections != null) ? Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_workSheet.Selections) : null;
            List <CellData> oldValues    = null;

            if ((_savedArrayFormulaViewportCells != null) && _savedArrayFormulaViewportCells.IsValueSaved())
            {
                oldValues = CopyMoveHelper.GetValues(_workSheet, _arrayFormulaRange.Row, _arrayFormulaRange.Column, _arrayFormulaRange.RowCount, _arrayFormulaRange.ColumnCount);
            }
            if ((oldValues != null) && object.ReferenceEquals(excel.ActiveSheet, _workSheet))
            {
                CopyMoveHelper.RaiseValueChanged(excel, _arrayFormulaRange.Row, _arrayFormulaRange.Column, _arrayFormulaRange.RowCount, _arrayFormulaRange.ColumnCount, oldValues);
            }
            CellRange[] newSelection = (_workSheet.Selections != null) ? Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)_workSheet.Selections) : null;
            if (excel.RaiseSelectionChanging(oldSelection, newSelection))
            {
                excel.RaiseSelectionChanged();
            }
            excel.RefreshCellAreaViewport(0, 0, _workSheet.RowCount, _workSheet.ColumnCount);
            excel.RefreshCharts();
            return(flag);
        }
Exemplo n.º 3
0
        public static void UndoCellsInfo(Worksheet sheet, CopyMoveCellsInfo cellsInfo, int baseRow, int baseColumn, SheetArea area)
        {
            int rowCount    = cellsInfo.RowCount;
            int columnCount = cellsInfo.ColumnCount;

            sheet.SuspendCalcService();
            try
            {
                for (int i = 0; i < rowCount; i++)
                {
                    for (int j = 0; j < columnCount; j++)
                    {
                        if (cellsInfo.IsFormulaSaved() && (area == SheetArea.Cells))
                        {
                            sheet.SetFormula(baseRow + i, baseColumn + j, null);
                        }
                        if (cellsInfo.IsSparklineSaved() && (area == SheetArea.Cells))
                        {
                            sheet.RemoveSparkline(baseRow + i, baseColumn + j);
                        }
                        if (cellsInfo.IsValueSaved())
                        {
                            sheet.SetValue(baseRow + i, baseColumn + j, area, null);
                        }
                        if (cellsInfo.IsStyleSaved())
                        {
                            SetStyleObject(sheet, baseRow + i, baseColumn + j, area, null);
                        }
                        if (cellsInfo.IsTagSaved())
                        {
                            sheet.SetTag(baseRow + i, baseColumn + j, area, null);
                        }
                    }
                }
                if (cellsInfo.IsFormulaSaved() && (area == SheetArea.Cells))
                {
                    foreach (CellData data in cellsInfo.GetFormulas())
                    {
                        sheet.SetFormula(baseRow + data.Row, baseColumn + data.Column, (string)(data.Value as string));
                    }
                }
                if (cellsInfo.IsSparklineSaved() && (area == SheetArea.Cells))
                {
                    foreach (CellData data2 in cellsInfo.GetSparklines())
                    {
                        SparklineInfo info = data2.Value as SparklineInfo;
                        if (info == null)
                        {
                            ((ISparklineSheet)sheet).SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, null);
                        }
                        else if (info.DataAxisRange == null)
                        {
                            sheet.SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, info.DataRange, info.Sparkline.DataOrientation, info.Sparkline.SparklineType, info.Sparkline.Setting);
                        }
                        else
                        {
                            sheet.SetSparkline(baseRow + data2.Row, baseColumn + data2.Column, info.DataRange, info.Sparkline.DataOrientation, info.Sparkline.SparklineType, info.DataAxisRange, info.Sparkline.DateAxisOrientation, info.Sparkline.Setting);
                        }
                    }
                }
                if (cellsInfo.IsValueSaved())
                {
                    foreach (CellData data3 in cellsInfo.GetValues())
                    {
                        sheet.SetValue(baseRow + data3.Row, baseColumn + data3.Column, area, data3.Value);
                    }
                }
                if (cellsInfo.IsStyleSaved())
                {
                    foreach (CellData data4 in cellsInfo.GetStyles())
                    {
                        SetStyleObject(sheet, baseRow + data4.Row, baseColumn + data4.Column, area, data4.Value);
                    }
                }
                if (cellsInfo.IsTagSaved())
                {
                    foreach (CellData data5 in cellsInfo.GetTags())
                    {
                        sheet.SetTag(baseRow + data5.Row, baseColumn + data5.Column, area, data5.Value);
                    }
                }
                if (cellsInfo.IsArrayFormulaSaved() && (area == SheetArea.Cells))
                {
                    object[,] arrayFormula = Excel.GetsArrayFormulas(sheet, baseRow, baseColumn, rowCount, columnCount);
                    if ((arrayFormula != null) && (arrayFormula.Length > 0))
                    {
                        int length = arrayFormula.GetLength(0);
                        for (int k = 0; k < length; k++)
                        {
                            CellRange range = (CellRange)arrayFormula[k, 0];
                            sheet.SetArrayFormula(range.Row, range.Column, range.RowCount, range.ColumnCount, null);
                        }
                    }
                    arrayFormula = cellsInfo.GetArrayFormula();
                    if ((arrayFormula != null) && (arrayFormula.Length > 0))
                    {
                        int num7 = arrayFormula.GetLength(0);
                        for (int m = 0; m < num7; m++)
                        {
                            CellRange range2  = (CellRange)arrayFormula[m, 0];
                            string    formula = (string)((string)arrayFormula[m, 1]);
                            if (formula.StartsWith("{") && formula.EndsWith("}"))
                            {
                                formula = formula.Substring(1, formula.Length - 2);
                            }
                            sheet.SetArrayFormula(range2.Row, range2.Column, range2.RowCount, range2.ColumnCount, formula);
                        }
                    }
                }
            }
            finally
            {
                sheet.ResumeCalcService();
            }
            SheetSpanModel spanModel = null;

            if (area == SheetArea.Cells)
            {
                spanModel = sheet.SpanModel;
            }
            else if (area == SheetArea.ColumnHeader)
            {
                spanModel = sheet.ColumnHeaderSpanModel;
            }
            else if (area == (SheetArea.CornerHeader | SheetArea.RowHeader))
            {
                spanModel = sheet.RowHeaderSpanModel;
            }
            if ((spanModel != null) && !spanModel.IsEmpty())
            {
                List <CellRange> list6      = new List <CellRange>();
                IEnumerator      enumerator = spanModel.GetEnumerator(baseRow, baseColumn, rowCount, columnCount);
                while (enumerator.MoveNext())
                {
                    CellRange current = enumerator.Current as CellRange;
                    if (current != null)
                    {
                        list6.Add(current);
                    }
                }
                foreach (CellRange range4 in list6)
                {
                    spanModel.Remove(range4.Row, range4.Column);
                }
            }
            if (cellsInfo.IsSpanSaved() && (spanModel != null))
            {
                foreach (CellRange range5 in cellsInfo.Spans)
                {
                    spanModel.Add(range5.Row, range5.Column, range5.RowCount, range5.ColumnCount);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Executes the action on the specified sender.
 /// </summary>
 /// <param name="sender">Object on which the action occurred.</param>
 public override void Execute(object sender)
 {
     if (Excel.IsValidRange(_dragDropExtent.FromRow, _dragDropExtent.FromColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount, _sheet.RowCount, _sheet.ColumnCount) && (_insert || Excel.IsValidRange(_dragDropExtent.ToRow, _dragDropExtent.ToColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount, _sheet.RowCount, _sheet.ColumnCount)))
     {
         SaveState();
         if (_insert)
         {
             if ((_dragDropExtent.FromColumn < 0) || (_dragDropExtent.FromRow < 0))
             {
                 if (_dragDropExtent.FromColumn < 0)
                 {
                     if (_dragDropExtent.FromRow >= 0)
                     {
                         int fromRow  = _dragDropExtent.FromRow;
                         int toRow    = _dragDropExtent.ToRow;
                         int rowCount = _dragDropExtent.RowCount;
                         int row      = _dragDropExtent.ToRow;
                         base.SuspendInvalidate(sender);
                         try
                         {
                             _sheet.AddRows(toRow, rowCount);
                             if (_copy)
                             {
                                 _sheet.CopyTo((toRow <= fromRow) ? (fromRow + rowCount) : fromRow, -1, toRow, -1, rowCount, -1, _option);
                             }
                             else
                             {
                                 _sheet.MoveTo((toRow <= fromRow) ? (fromRow + rowCount) : fromRow, -1, toRow, -1, rowCount, -1, _option);
                                 _sheet.RemoveRows((toRow <= fromRow) ? (fromRow + rowCount) : fromRow, rowCount);
                                 if (fromRow < toRow)
                                 {
                                     row = toRow - rowCount;
                                 }
                             }
                         }
                         finally
                         {
                             base.ResumeInvalidate(sender);
                         }
                         Excel view2 = sender as Excel;
                         if (view2 != null)
                         {
                             CellRange[] oldSelection = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)view2.ActiveSheet.Selections);
                             view2.SetSelection(row, -1, rowCount, -1);
                             if (view2.RaiseSelectionChanging(oldSelection, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)view2.ActiveSheet.Selections)))
                             {
                                 view2.RaiseSelectionChanged();
                             }
                             view2.SetActiveCell(row, 0, false);
                             view2.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
                             view2.RefreshFloatingObjects();
                         }
                     }
                 }
                 else
                 {
                     int fromColumn  = _dragDropExtent.FromColumn;
                     int toColumn    = _dragDropExtent.ToColumn;
                     int columnCount = _dragDropExtent.ColumnCount;
                     int column      = _dragDropExtent.ToColumn;
                     base.SuspendInvalidate(sender);
                     try
                     {
                         _sheet.AddColumns(toColumn, columnCount);
                         if (_copy)
                         {
                             _sheet.CopyTo(-1, (toColumn <= fromColumn) ? (fromColumn + columnCount) : fromColumn, -1, toColumn, -1, columnCount, _option);
                         }
                         else
                         {
                             _sheet.MoveTo(-1, (toColumn <= fromColumn) ? (fromColumn + columnCount) : fromColumn, -1, toColumn, -1, columnCount, _option);
                             _sheet.RemoveColumns((toColumn <= fromColumn) ? (fromColumn + columnCount) : fromColumn, columnCount);
                             if (fromColumn < toColumn)
                             {
                                 column = toColumn - columnCount;
                             }
                         }
                     }
                     finally
                     {
                         base.ResumeInvalidate(sender);
                     }
                     Excel view = sender as Excel;
                     if (view != null)
                     {
                         CellRange[] rangeArray = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)view.ActiveSheet.Selections);
                         view.SetSelection(-1, column, -1, columnCount);
                         if (view.RaiseSelectionChanging(rangeArray, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)view.ActiveSheet.Selections)))
                         {
                             view.RaiseSelectionChanged();
                         }
                         view.SetActiveCell(0, column, false);
                         view.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
                         view.RefreshFloatingObjects();
                     }
                 }
             }
         }
         else
         {
             int   num9      = _dragDropExtent.FromRow;
             int   num10     = _dragDropExtent.FromColumn;
             int   num11     = _dragDropExtent.ToRow;
             int   num12     = _dragDropExtent.ToColumn;
             int   num13     = _dragDropExtent.RowCount;
             int   num14     = _dragDropExtent.ColumnCount;
             Excel sheetView = sender as Excel;
             base.SuspendInvalidate(sender);
             try
             {
                 if (_copy)
                 {
                     _sheet.CopyTo(num9, num10, num11, num12, num13, num14, _option);
                 }
                 else
                 {
                     _sheet.MoveTo(num9, num10, num11, num12, num13, num14, _option);
                 }
                 if (sheetView != null)
                 {
                     CellRange[] rangeArray3 = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections);
                     sheetView.SetSelection(num11, num12, num13, num14);
                     if (sheetView.RaiseSelectionChanging(rangeArray3, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections)))
                     {
                         sheetView.RaiseSelectionChanged();
                     }
                     sheetView.SetActiveCell(Math.Max(0, num11), Math.Max(0, num12), false);
                     if ((!_copy && (_savedFromViewportCells != null)) && _savedFromViewportCells.IsValueSaved())
                     {
                         CopyMoveHelper.RaiseValueChanged(sheetView, num9, num10, num13, num14, _savedFromViewportCells.GetValues());
                     }
                     if ((_savedToViewportCells != null) && _savedToViewportCells.IsValueSaved())
                     {
                         CopyMoveHelper.RaiseValueChanged(sheetView, num11, num12, num13, num14, _savedToViewportCells.GetValues());
                     }
                 }
             }
             finally
             {
                 base.ResumeInvalidate(sender);
             }
             if (sheetView != null)
             {
                 sheetView.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
                 sheetView.RefreshFloatingObjects();
             }
         }
     }
 }