Example #1
0
 void OnEditedCellChanged(object sender, CellChangedEventArgs e)
 {
     if ((_excel != null) && string.Equals(e.PropertyName, "Value"))
     {
         CellRange range  = FixRange(Worksheet, ClearRange);
         int       row    = e.Row - range.Row;
         int       column = e.Column - range.Column;
         ulong     num3   = CopyMoveHelper.ConvertToKey(row, column);
         if (_cachedValues.ContainsKey(num3))
         {
             CellValueEntry entry = _cachedValues[num3];
             if (entry.Value is string)
             {
                 if (!string.IsNullOrEmpty((string)(entry.Value as string)))
                 {
                     _excel.RaiseValueChanged(e.Row, e.Column);
                 }
             }
             else if (entry.Value != null)
             {
                 _excel.RaiseValueChanged(e.Row, e.Column);
             }
         }
     }
 }
Example #2
0
        bool Undo(Excel excel)
        {
            bool flag;

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

            if ((_savedFilledViewportCells != null) && _savedFilledViewportCells.IsValueSaved())
            {
                oldValues = CopyMoveHelper.GetValues(_workSheet, fillRange.Row, fillRange.Column, fillRange.RowCount, fillRange.ColumnCount);
            }
            if (_dragFillExtent.AutoFillType == AutoFillType.ClearValues)
            {
                flag = UndoDragClear(excel);
            }
            else
            {
                flag = UndoDragFill(excel);
            }
            excel.CloseDragFillPopup();
            if ((oldValues != null) && object.ReferenceEquals(excel.ActiveSheet, _workSheet))
            {
                CopyMoveHelper.RaiseValueChanged(excel, fillRange.Row, fillRange.Column, fillRange.RowCount, fillRange.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);
            return(flag);
        }
Example #3
0
        /// <summary>
        /// Saves the state for undoing the action before executing the action.
        /// </summary>
        public void SaveState()
        {
            CellRange         range     = AdjustRange(_arrayFormulaRange);
            CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(range.RowCount, range.ColumnCount);

            CopyMoveHelper.SaveViewportInfo(_workSheet, cellsInfo, range.Row, range.Column, CopyToOption.All);
            _savedArrayFormulaViewportCells = cellsInfo;
        }
Example #4
0
        CopyMoveCellsInfo SaveRangeStates(CellRange range)
        {
            CellRange         range2    = AdjustRange(range);
            CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(range2.RowCount, range2.ColumnCount);

            CopyMoveHelper.SaveViewportInfo(_workSheet, cellsInfo, range2.Row, range2.Column, CopyToOption.All);
            return(cellsInfo);
        }
Example #5
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();
     }
 }
Example #6
0
 bool UndoSetArrayFormula(Excel excel)
 {
     base.SuspendInvalidate(excel);
     _workSheet.SuspendCalcService();
     try
     {
         using (((IUIActionExecuter)_workSheet).BeginUIAction())
         {
             excel.ActiveSheet.SetArrayFormula(_arrayFormulaRange.Row, _arrayFormulaRange.Column, _arrayFormulaRange.RowCount, _arrayFormulaRange.ColumnCount, null);
         }
         CellRange range  = new CellRange(_arrayFormulaRange.Row, _arrayFormulaRange.Column, _arrayFormulaRange.RowCount, _arrayFormulaRange.ColumnCount);
         CellRange range2 = AdjustRange(range);
         CopyMoveHelper.UndoCellsInfo(_workSheet, _savedArrayFormulaViewportCells, range2.Row, range2.Column, SheetArea.Cells);
         excel.SetActiveCell(Math.Max(0, range.Row), Math.Max(0, range.Column), true);
         _workSheet.SetSelection(range);
     }
     finally
     {
         _workSheet.ResumeCalcService();
         base.ResumeInvalidate(excel);
     }
     excel.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
     return(true);
 }
Example #7
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);
        }
Example #8
0
 public bool Undo(object parameter)
 {
     if (Worksheet != null)
     {
         bool flag = false;
         if ((_cachedTables != null) && (_cachedTables.Count > 0))
         {
             foreach (SheetTable table in _cachedTables)
             {
                 CellRange range       = table.Range;
                 int       row         = range.Row;
                 int       column      = range.Column;
                 int       rowCount    = range.RowCount;
                 int       columnCount = range.ColumnCount;
                 if (!table.ShowHeader)
                 {
                     row--;
                     rowCount++;
                 }
                 if (table.ShowFooter)
                 {
                     rowCount--;
                 }
                 SheetTable table2 = Worksheet.AddTable(table.Name, row, column, rowCount, columnCount, table.Style);
                 table2.BandedColumns        = table.BandedColumns;
                 table2.BandedRows           = table.BandedRows;
                 table2.HighlightFirstColumn = table.HighlightFirstColumn;
                 table2.HighlightLastColumn  = table.HighlightLastColumn;
                 table2.ShowFooter           = table.ShowFooter;
                 table2.ShowHeader           = table.ShowHeader;
             }
         }
         CellRange range2 = FixRange(Worksheet, ClearRange);
         if (((_cachedValues != null) && (range2.ColumnCount > 0)) && (range2.RowCount > 0))
         {
             try
             {
                 _excel = parameter as Excel;
                 Worksheet.CellChanged += new EventHandler <CellChangedEventArgs>(OnEditedCellChanged);
                 int num5 = range2.RowCount;
                 int num6 = range2.ColumnCount;
                 for (int i = 0; i < num5; i++)
                 {
                     for (int j = 0; j < num6; j++)
                     {
                         int   num9  = range2.Row + i;
                         int   num10 = range2.Column + j;
                         ulong num11 = CopyMoveHelper.ConvertToKey(i, j);
                         if (_cachedValues.ContainsKey(num11))
                         {
                             CellValueEntry entry = _cachedValues[num11];
                             if (entry.IsFormula)
                             {
                                 Worksheet.SetFormula(num9, num10, (string)(entry.Value as string));
                             }
                             else
                             {
                                 Worksheet.SetFormula(num9, num10, null);
                                 Worksheet.SetValue(num9, num10, entry.Value);
                             }
                         }
                         else
                         {
                             Worksheet.SetFormula(num9, num10, null);
                             Worksheet.SetValue(num9, num10, null);
                         }
                     }
                 }
                 foreach (KeyValuePair <CellRange, string> pair in _arrayFormulas)
                 {
                     Worksheet.SetArrayFormula(pair.Key.Row, pair.Key.Column, pair.Key.RowCount, pair.Key.ColumnCount, pair.Value);
                 }
                 flag = true;
             }
             finally
             {
                 Worksheet.CellChanged -= new EventHandler <CellChangedEventArgs>(OnEditedCellChanged);
                 _excel = null;
             }
         }
         if (((_cachedFilteredColumns != null) && (_cachedFilteredColumns.Count > 0)) && (Worksheet.RowFilter != null))
         {
             foreach (int num12 in _cachedFilteredColumns)
             {
                 Worksheet.RowFilter.Filter(num12);
             }
         }
         if (flag)
         {
             RefreshUI(parameter);
             return(true);
         }
     }
     return(false);
 }
Example #9
0
 public void SaveState()
 {
     if (Worksheet != null)
     {
         _cachedTables = new List <SheetTable>();
         SheetTable[] tables = Worksheet.GetTables();
         if ((tables != null) && (tables.Length > 0))
         {
             foreach (SheetTable table in tables)
             {
                 if (ClearRange.Contains(table.Range))
                 {
                     _cachedTables.Add(table);
                 }
             }
         }
         _cachedFilteredColumns = new List <int>();
         RowFilterBase rowFilter = Worksheet.RowFilter;
         if (((rowFilter != null) && (rowFilter.Range != null)) && rowFilter.IsFiltered)
         {
             int row      = rowFilter.Range.Row;
             int rowCount = rowFilter.Range.RowCount;
             if (rowFilter.ShowFilterButton)
             {
                 row      = rowFilter.Range.Row - 1;
                 rowCount = rowFilter.Range.RowCount + 1;
                 if (row < 0)
                 {
                     row      = -1;
                     rowCount = -1;
                 }
             }
             if (ClearRange.Contains(row, rowFilter.Range.Column, rowCount, rowFilter.Range.ColumnCount))
             {
                 int num3 = (rowFilter.Range.Column < 0) ? 0 : rowFilter.Range.Column;
                 int num4 = (rowFilter.Range.Column < 0) ? Worksheet.ColumnCount : rowFilter.Range.ColumnCount;
                 for (int i = 0; i < num4; i++)
                 {
                     if (rowFilter.IsColumnFiltered(num3 + i))
                     {
                         _cachedFilteredColumns.Add(num3 + i);
                     }
                 }
             }
         }
         CellRange range = FixRange(Worksheet, ClearRange);
         if ((range.ColumnCount > 0) && (range.RowCount > 0))
         {
             List <CellRange> list  = new List <CellRange>();
             List <string>    list2 = new List <string>();
             object[,] objArray = Worksheet.FindFormulas(range.Row, range.Column, range.RowCount, range.ColumnCount);
             for (int j = 0; j < objArray.GetLength(0); j++)
             {
                 CellRange range2 = objArray[j, 0] as CellRange;
                 string    str    = (string)(objArray[j, 1] as string);
                 Match     match  = new Regex(@"^\s*{\s*(.*?)}\s*$").Match(str);
                 if (((match.Success && (range2.Row >= range.Row)) && ((range2.Column >= range.Column) && ((range2.Row + range2.RowCount) <= (range.Row + range.RowCount)))) && ((range2.Column + range2.ColumnCount) <= (range.Column + range.ColumnCount)))
                 {
                     _arrayFormulas[range2] = match.Groups[1].Value;
                     list.Add(range2);
                     list2.Add(str);
                 }
             }
             _cachedValues = new Dictionary <ulong, CellValueEntry>();
             for (int k = 0; k < range.RowCount; k++)
             {
                 for (int m = 0; m < range.ColumnCount; m++)
                 {
                     int  num9   = range.Row + k;
                     int  column = range.Column + m;
                     bool flag   = false;
                     foreach (CellRange range3 in list)
                     {
                         if (range3.Contains(num9, column))
                         {
                             column = (range3.Column + range3.ColumnCount) - 1;
                             flag   = true;
                             break;
                         }
                     }
                     if (!flag)
                     {
                         string formula = Worksheet.GetFormula(num9, column);
                         if (!string.IsNullOrEmpty(formula))
                         {
                             _cachedValues.Add(CopyMoveHelper.ConvertToKey(k, m), new CellValueEntry(formula, true));
                         }
                         else
                         {
                             object obj2 = Worksheet.GetValue(num9, column);
                             if (obj2 != null)
                             {
                                 _cachedValues.Add(CopyMoveHelper.ConvertToKey(k, m), new CellValueEntry(obj2, false));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #10
0
        void UndoRangeStates(CopyMoveCellsInfo savedInfo, CellRange range)
        {
            CellRange range2 = AdjustRange(range);

            CopyMoveHelper.UndoCellsInfo(_workSheet, savedInfo, range2.Row, range2.Column, SheetArea.Cells);
        }
Example #11
0
        void ExecuteDragFill(Excel excel)
        {
            CellRange startRange = _dragFillExtent.StartRange;
            CellRange fillRange  = _dragFillExtent.FillRange;

            if (_dragFillExtent.AutoFillType == AutoFillType.FillSeries)
            {
                ClearData(fillRange);
                if ((_dragFillExtent.FillDirection == FillDirection.Down) || (_dragFillExtent.FillDirection == FillDirection.Right))
                {
                    _workSheet.FillAuto(_wholeFillRange, _fillSeries);
                }
                else
                {
                    _workSheet.FillLinear(_wholeFillRange, _fillSeries);
                }
            }
            else if (_dragFillExtent.AutoFillType == AutoFillType.CopyCells)
            {
                CopyCells(startRange, fillRange, CopyToOption.All);
            }
            else if (_dragFillExtent.AutoFillType == AutoFillType.FillFormattingOnly)
            {
                CopyCells(startRange, fillRange, CopyToOption.Style);
            }
            else if (_dragFillExtent.AutoFillType == AutoFillType.FillWithoutFormatting)
            {
                ClearData(fillRange);
                if ((((startRange.RowCount == 1) && (startRange.ColumnCount == 1)) && ((startRange.Row != -1) || (startRange.Column == -1))) && ((startRange.Column != -1) || (startRange.Row == -1)))
                {
                    CopyToOption copyOption = CopyToOption.Tag | CopyToOption.Span | CopyToOption.Sparkline | CopyToOption.RangeGroup | CopyToOption.Formula | CopyToOption.Value;
                    CopyCells(startRange, fillRange, copyOption);
                }
                else
                {
                    CellRange range3 = AdjustRange(_wholeFillRange);
                    object[,] objArray = new object[range3.RowCount, range3.ColumnCount];
                    for (int i = 0; i < range3.RowCount; i++)
                    {
                        for (int k = 0; k < range3.ColumnCount; k++)
                        {
                            objArray[i, k] = CopyMoveHelper.GetStyleObject(_workSheet, range3.Row + i, range3.Column + k, SheetArea.Cells);
                        }
                    }
                    if ((_dragFillExtent.FillDirection == FillDirection.Down) || (_dragFillExtent.FillDirection == FillDirection.Right))
                    {
                        _workSheet.FillAuto(_wholeFillRange, _fillSeries);
                    }
                    else
                    {
                        _workSheet.FillLinear(_wholeFillRange, _fillSeries);
                    }
                    for (int j = 0; j < range3.RowCount; j++)
                    {
                        for (int m = 0; m < range3.ColumnCount; m++)
                        {
                            CopyMoveHelper.SetStyleObject(_workSheet, range3.Row + j, range3.Column + m, SheetArea.Cells, objArray[j, m]);
                        }
                    }
                }
            }
            excel.SetActiveCell(Math.Max(0, _wholeFillRange.Row), Math.Max(0, _wholeFillRange.Column), true);
            _workSheet.SetSelection(_wholeFillRange);
        }
Example #12
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 #13
0
        /// <summary>
        /// Undoes the action of the saved information.
        /// </summary>
        /// <param name="parameter">The parameter to undo the action on. </param>
        /// <returns>
        /// <c>true</c> if the undo action succeeds; otherwise, <c>false</c>.
        /// </returns>
        public bool Undo(object parameter)
        {
            if (!Excel.IsValidRange(_dragDropExtent.FromRow, _dragDropExtent.FromColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount, _sheet.RowCount, _sheet.ColumnCount))
            {
                return(false);
            }
            if (!_insert && !Excel.IsValidRange(_dragDropExtent.ToRow, _dragDropExtent.ToColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount, _sheet.RowCount, _sheet.ColumnCount))
            {
                return(false);
            }
            bool  flag      = false;
            Excel sheetView = parameter as Excel;

            if (_insert)
            {
                if ((_dragDropExtent.FromColumn < 0) || (_dragDropExtent.FromRow < 0))
                {
                    if (_dragDropExtent.FromColumn >= 0)
                    {
                        int fromColumn  = _dragDropExtent.FromColumn;
                        int columnCount = _dragDropExtent.ColumnCount;
                        base.SuspendInvalidate(parameter);
                        try
                        {
                            if (_copy)
                            {
                                _sheet.RemoveColumns(_dragDropExtent.ToColumn, columnCount);
                            }
                            else
                            {
                                int toColumn = _dragDropExtent.ToColumn;
                                int column   = _dragDropExtent.FromColumn;
                                if (_dragDropExtent.FromColumn < _dragDropExtent.ToColumn)
                                {
                                    toColumn = _dragDropExtent.ToColumn - columnCount;
                                }
                                else
                                {
                                    column = _dragDropExtent.FromColumn + columnCount;
                                }
                                _sheet.AddColumns(column, columnCount);
                                _sheet.CopyTo(-1, (column <= toColumn) ? (toColumn + columnCount) : toColumn, -1, column, -1, columnCount, _option);
                                _sheet.RemoveColumns((column <= toColumn) ? (toColumn + columnCount) : toColumn, columnCount);
                                if (toColumn < column)
                                {
                                    fromColumn = column - columnCount;
                                }
                            }
                        }
                        finally
                        {
                            base.ResumeInvalidate(parameter);
                        }
                        if (sheetView != null)
                        {
                            CellRange[] oldSelection = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections);
                            sheetView.SetSelection(-1, fromColumn, -1, columnCount);
                            if (sheetView.RaiseSelectionChanging(oldSelection, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections)))
                            {
                                sheetView.RaiseSelectionChanged();
                            }
                            sheetView.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
                            sheetView.RefreshFloatingObjects();
                        }
                        flag = true;
                    }
                    else if (_dragDropExtent.FromRow >= 0)
                    {
                        int rowCount = _dragDropExtent.RowCount;
                        int fromRow  = _dragDropExtent.FromRow;
                        base.SuspendInvalidate(parameter);
                        try
                        {
                            if (_copy)
                            {
                                _sheet.RemoveRows(_dragDropExtent.ToRow, rowCount);
                            }
                            else
                            {
                                int toRow = _dragDropExtent.ToRow;
                                int row   = _dragDropExtent.FromRow;
                                if (_dragDropExtent.FromRow < _dragDropExtent.ToRow)
                                {
                                    toRow = _dragDropExtent.ToRow - rowCount;
                                }
                                else
                                {
                                    row = _dragDropExtent.FromRow + rowCount;
                                }
                                _sheet.AddRows(row, rowCount);
                                if (_savedFromViewportCells != null)
                                {
                                    CopyMoveHelper.UndoCellsInfo(_sheet, _savedFromViewportCells, row, 0, SheetArea.Cells);
                                    flag = true;
                                }
                                if (_savedFromRowHeaderCells != null)
                                {
                                    CopyMoveHelper.UndoCellsInfo(_sheet, _savedFromRowHeaderCells, row, 0, SheetArea.CornerHeader | SheetArea.RowHeader);
                                    flag = true;
                                }
                                if (_savedFromRows != null)
                                {
                                    CopyMoveHelper.UndoRowsInfo(_sheet, _savedFromRows, row);
                                    flag = true;
                                }
                                if (!flag)
                                {
                                    _sheet.MoveTo((row <= toRow) ? (toRow + rowCount) : toRow, -1, row, -1, rowCount, -1, _option);
                                }
                                _sheet.RemoveRows((row <= toRow) ? (toRow + rowCount) : toRow, rowCount);
                                if (toRow < row)
                                {
                                    fromRow = row - rowCount;
                                }
                            }
                        }
                        finally
                        {
                            base.ResumeInvalidate(parameter);
                        }
                        if (sheetView != null)
                        {
                            CellRange[] rangeArray2 = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections);
                            sheetView.SetSelection(fromRow, -1, rowCount, -1);
                            if (sheetView.RaiseSelectionChanging(rangeArray2, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections)))
                            {
                                sheetView.RaiseSelectionChanged();
                            }
                            sheetView.RefreshAll();
                            sheetView.UpdateLayout();
                            sheetView.RefreshFloatingObjects();
                        }
                        flag = true;
                    }
                }
            }
            else
            {
                int             num9      = (_dragDropExtent.FromRow < 0) ? 0 : _dragDropExtent.FromRow;
                int             num10     = (_dragDropExtent.FromColumn < 0) ? 0 : _dragDropExtent.FromColumn;
                int             num11     = (_dragDropExtent.ToRow < 0) ? 0 : _dragDropExtent.ToRow;
                int             num12     = (_dragDropExtent.ToColumn < 0) ? 0 : _dragDropExtent.ToColumn;
                int             num13     = (_dragDropExtent.FromRow < 0) ? _sheet.RowCount : _dragDropExtent.RowCount;
                int             num14     = (_dragDropExtent.FromColumn < 0) ? _sheet.ColumnCount : _dragDropExtent.ColumnCount;
                List <CellData> oldValues = null;
                List <CellData> list2     = null;
                if ((!_copy && (_savedFromViewportCells != null)) && _savedFromViewportCells.IsValueSaved())
                {
                    list2 = CopyMoveHelper.GetValues(_sheet, num9, num10, num13, num14);
                }
                if ((_savedToViewportCells != null) && _savedToViewportCells.IsValueSaved())
                {
                    oldValues = CopyMoveHelper.GetValues(_sheet, num11, num12, num13, num14);
                }
                base.SuspendInvalidate(parameter);
                try
                {
                    if (_savedToColumnHeaderCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedToColumnHeaderCells, 0, num12, SheetArea.ColumnHeader);
                        flag = true;
                    }
                    if (_savedToColumns != null)
                    {
                        CopyMoveHelper.UndoColumnsInfo(_sheet, _savedToColumns, num12);
                        flag = true;
                    }
                    if (_savedToViewportCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedToViewportCells, num11, num12, SheetArea.Cells);
                        flag = true;
                    }
                    if (_savedToRowHeaderCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedToRowHeaderCells, num11, 0, SheetArea.CornerHeader | SheetArea.RowHeader);
                        flag = true;
                    }
                    if (_savedToRows != null)
                    {
                        CopyMoveHelper.UndoRowsInfo(_sheet, _savedToRows, num11);
                        flag = true;
                    }
                    if (_savedToFloatingObjects != null)
                    {
                        CopyMoveHelper.UndoFloatingObjectsInfo(_sheet, _savedToFloatingObjects);
                        sheetView.RefreshFloatingObjects();
                        flag = true;
                    }
                    if (_savedFromColumnHeaderCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedFromColumnHeaderCells, 0, num10, SheetArea.ColumnHeader);
                        flag = true;
                    }
                    if (_savedFromColumns != null)
                    {
                        CopyMoveHelper.UndoColumnsInfo(_sheet, _savedFromColumns, num10);
                        flag = true;
                    }
                    if (_savedFromViewportCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedFromViewportCells, num9, num10, SheetArea.Cells);
                        flag = true;
                    }
                    if (_savedFromRowHeaderCells != null)
                    {
                        CopyMoveHelper.UndoCellsInfo(_sheet, _savedFromRowHeaderCells, num9, 0, SheetArea.CornerHeader | SheetArea.RowHeader);
                        flag = true;
                    }
                    if (_savedFromRows != null)
                    {
                        CopyMoveHelper.UndoRowsInfo(_sheet, _savedFromRows, num9);
                        flag = true;
                    }
                    if (_savedFromFloatingObjects != null)
                    {
                        CopyMoveHelper.UndoFloatingObjectsInfo(_sheet, _savedFromFloatingObjects);
                        sheetView.RefreshFloatingObjects();
                        flag = true;
                    }
                }
                finally
                {
                    base.ResumeInvalidate(parameter);
                }
                if (flag && (sheetView != null))
                {
                    CellRange[] rangeArray3 = Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections);
                    sheetView.SetSelection(_dragDropExtent.FromRow, _dragDropExtent.FromColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount);
                    if (sheetView.RaiseSelectionChanging(rangeArray3, Enumerable.ToArray <CellRange>((IEnumerable <CellRange>)sheetView.ActiveSheet.Selections)))
                    {
                        sheetView.RaiseSelectionChanged();
                    }
                    if (oldValues != null)
                    {
                        CopyMoveHelper.RaiseValueChanged(sheetView, num11, num12, num13, num14, oldValues);
                    }
                    if (list2 != null)
                    {
                        CopyMoveHelper.RaiseValueChanged(sheetView, num9, num10, num13, num14, list2);
                    }
                    sheetView.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader | SheetArea.RowHeader);
                    sheetView.RefreshFloatingObjects();
                }
            }
            if (flag && (sheetView != null))
            {
                if ((_savedAcitveRowViewportIndex != -2) && (_savedAcitveColumnViewportIndex != -2))
                {
                    sheetView.SetActiveRowViewportIndex(_savedAcitveRowViewportIndex);
                    sheetView.SetActiveColumnViewportIndex(_savedAcitveColumnViewportIndex);
                }
                if ((_savedActiveRow != -1) && (_savedActiveColumn != -1))
                {
                    CellRange range = sheetView.ActiveSheet.Selections[0];
                    if (range.Contains(_savedActiveRow, _savedActiveColumn))
                    {
                        sheetView.SetActiveCell(_savedActiveRow, _savedActiveColumn, false);
                    }
                    else
                    {
                        sheetView.SetActiveCell(Math.Max(0, range.Row), Math.Max(0, range.Column), false);
                    }
                }
                if (((_savedAcitveRowViewportIndex != -2) && (_savedAcitveColumnViewportIndex != -2)) && ((_savedActiveRow != -1) && (_savedActiveColumn != -1)))
                {
                    sheetView.ShowCell(_savedAcitveRowViewportIndex, _savedAcitveColumnViewportIndex, _savedActiveRow, _savedActiveColumn, VerticalPosition.Nearest, HorizontalPosition.Nearest);
                }
            }
            return(flag);
        }
Example #14
0
        /// <summary>
        /// Saves the state for undoing the action.
        /// </summary>
        public void SaveState()
        {
            InitSaveState();
            int baseRow     = (_dragDropExtent.FromRow < 0) ? 0 : _dragDropExtent.FromRow;
            int baseColumn  = (_dragDropExtent.FromColumn < 0) ? 0 : _dragDropExtent.FromColumn;
            int row         = (_dragDropExtent.ToRow < 0) ? 0 : _dragDropExtent.ToRow;
            int num4        = (_dragDropExtent.ToColumn < 0) ? 0 : _dragDropExtent.ToColumn;
            int rowCount    = (_dragDropExtent.FromRow < 0) ? _sheet.RowCount : _dragDropExtent.RowCount;
            int columnCount = (_dragDropExtent.FromColumn < 0) ? _sheet.ColumnCount : _dragDropExtent.ColumnCount;

            if (_insert)
            {
                if (((_dragDropExtent.FromColumn < 0) || (_dragDropExtent.FromRow < 0)) && (((_dragDropExtent.FromColumn < 0) && (_dragDropExtent.FromRow >= 0)) && (!_copy && Excel.HasTable(_sheet, row, -1, 1, -1, true))))
                {
                    CopyMoveCellsInfo headerCellsInfo = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                    CopyMoveRowsInfo  rowsInfo        = new CopyMoveRowsInfo(rowCount);
                    CopyMoveHelper.SaveRowHeaderInfo(_sheet, headerCellsInfo, rowsInfo, baseRow, _option);
                    _savedFromRowHeaderCells = headerCellsInfo;
                    _savedFromRows           = rowsInfo;
                    CopyMoveCellsInfo cellsInfo = new CopyMoveCellsInfo(rowCount, columnCount);
                    CopyMoveHelper.SaveViewportInfo(_sheet, cellsInfo, baseRow, baseColumn, _option);
                    _savedFromViewportCells = cellsInfo;
                }
            }
            else
            {
                if (_dragDropExtent.FromRow < 0)
                {
                    CopyMoveCellsInfo   info4       = new CopyMoveCellsInfo(_sheet.ColumnHeader.RowCount, columnCount);
                    CopyMoveColumnsInfo columnsInfo = new CopyMoveColumnsInfo(columnCount);
                    CopyMoveHelper.SaveColumnHeaderInfo(_sheet, info4, columnsInfo, num4, _option);
                    _savedToColumnHeaderCells = info4;
                    _savedToColumns           = columnsInfo;
                    if (!_copy)
                    {
                        CopyMoveCellsInfo   info6 = new CopyMoveCellsInfo(_sheet.ColumnHeader.RowCount, columnCount);
                        CopyMoveColumnsInfo info7 = new CopyMoveColumnsInfo(columnCount);
                        CopyMoveHelper.SaveColumnHeaderInfo(_sheet, info6, info7, baseColumn, _option);
                        _savedFromColumnHeaderCells = info6;
                        _savedFromColumns           = info7;
                    }
                }
                if (_dragDropExtent.FromColumn < 0)
                {
                    CopyMoveCellsInfo info8 = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                    CopyMoveRowsInfo  info9 = new CopyMoveRowsInfo(rowCount);
                    CopyMoveHelper.SaveRowHeaderInfo(_sheet, info8, info9, row, _option);
                    _savedToRowHeaderCells = info8;
                    _savedToRows           = info9;
                    if (!_copy)
                    {
                        CopyMoveCellsInfo info10 = new CopyMoveCellsInfo(rowCount, _sheet.RowHeader.ColumnCount);
                        CopyMoveRowsInfo  info11 = new CopyMoveRowsInfo(rowCount);
                        CopyMoveHelper.SaveRowHeaderInfo(_sheet, info10, info11, baseRow, _option);
                        _savedFromRowHeaderCells = info10;
                        _savedFromRows           = info11;
                    }
                }
                CopyMoveCellsInfo info12 = new CopyMoveCellsInfo(rowCount, columnCount);
                CopyMoveHelper.SaveViewportInfo(_sheet, info12, row, num4, _option);
                _savedToViewportCells = info12;
                if (!_copy)
                {
                    CopyMoveCellsInfo info13 = new CopyMoveCellsInfo(rowCount, columnCount);
                    CopyMoveHelper.SaveViewportInfo(_sheet, info13, baseRow, baseColumn, _option);
                    _savedFromViewportCells = info13;
                    if ((_option & CopyToOption.FloatingObject) > ((CopyToOption)0))
                    {
                        CellRange        range = new CellRange(_dragDropExtent.FromRow, _dragDropExtent.FromColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount);
                        FloatingObject[] floatingObjectsInRange = CopyMoveHelper.GetFloatingObjectsInRange(CopyMoveHelper.AdjustRange(range, _sheet.RowCount, _sheet.ColumnCount), _sheet);
                        _savedFromFloatingObjects = new CopyMoveFloatingObjectsInfo();
                        _savedFromFloatingObjects.SaveFloatingObjects(range, floatingObjectsInRange);
                    }
                }
                if ((_option & CopyToOption.FloatingObject) > ((CopyToOption)0))
                {
                    CellRange        range3          = new CellRange(_dragDropExtent.ToRow, _dragDropExtent.ToColumn, _dragDropExtent.RowCount, _dragDropExtent.ColumnCount);
                    FloatingObject[] floatingObjects = CopyMoveHelper.GetFloatingObjectsInRange(CopyMoveHelper.AdjustRange(range3, _sheet.RowCount, _sheet.ColumnCount), _sheet);
                    _savedToFloatingObjects = new CopyMoveFloatingObjectsInfo();
                    _savedToFloatingObjects.SaveFloatingObjects(range3, floatingObjects);
                }
            }
            _savedAcitveRowViewportIndex    = _sheet.GetActiveRowViewportIndex();
            _savedAcitveColumnViewportIndex = _sheet.GetActiveColumnViewportIndex();
            _savedActiveRow    = _sheet.ActiveRowIndex;
            _savedActiveColumn = _sheet.ActiveColumnIndex;
        }