Example #1
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();
             }
         }
     }
 }
Example #2
0
        void OnAddCol(object sender, RoutedEventArgs e)
        {
            Worksheet sheet = _excel.ActiveSheet;

            sheet.AddColumns(sheet.ActiveColumnIndex, 1);
        }