void InitSaveState() { _savedFromColumnHeaderCells = null; _savedFromColumns = null; _savedFromViewportCells = null; _savedFromRowHeaderCells = null; _savedFromRows = null; _savedFromFloatingObjects = null; _savedToColumnHeaderCells = null; _savedToColumns = null; _savedToViewportCells = null; _savedToRowHeaderCells = null; _savedToRows = null; _savedToFloatingObjects = null; _savedAcitveRowViewportIndex = -2; _savedAcitveColumnViewportIndex = -2; _savedActiveRow = -1; _savedActiveColumn = -1; }
public static void UndoColumnsInfo(Worksheet sheet, CopyMoveColumnsInfo columnsInfo, int baseColumn) { int columnCount = columnsInfo.ColumnCount; if (columnsInfo.IsBindingFieldSaved()) { for (int i = 0; i < columnCount; i++) { string str; if (columnsInfo.GetBindingField(i, out str)) { sheet.BindDataColumn(baseColumn + i, str); } } } else { for (int j = 0; j < columnCount; j++) { sheet.BindDataColumn(baseColumn + j, null); } } if (columnsInfo.IsWidthSaved()) { for (int k = 0; k < columnCount; k++) { sheet.SetColumnWidth(baseColumn + k, SheetArea.Cells, columnsInfo.GetWidth(k)); } } if (columnsInfo.IsVisibleSaved()) { for (int m = 0; m < columnCount; m++) { sheet.SetColumnVisible(baseColumn + m, SheetArea.Cells, columnsInfo.GetVisible(m)); } } if (columnsInfo.IsResizableSaved()) { for (int n = 0; n < columnCount; n++) { sheet.SetColumnResizable(baseColumn + n, SheetArea.Cells, columnsInfo.GetResizable(n)); } } if (columnsInfo.IsTagSaved()) { for (int num7 = 0; num7 < columnCount; num7++) { sheet.SetTag(-1, baseColumn + num7, SheetArea.Cells, columnsInfo.GetTag(num7)); } } if (columnsInfo.IsViewportColumnStyleSaved()) { for (int num8 = 0; num8 < columnCount; num8++) { SetStyleObject(sheet, -1, baseColumn + num8, SheetArea.Cells, columnsInfo.GetViewportColumnStyle(num8)); } } if (columnsInfo.IsHeaderColumnStyleSaved()) { for (int num9 = 0; num9 < columnCount; num9++) { SetStyleObject(sheet, -1, baseColumn + num9, SheetArea.ColumnHeader, columnsInfo.GetHeaderColumnStyle(num9)); } } if (columnsInfo.IsRangeGroupSaved()) { RangeGroup columnRangeGroup = sheet.ColumnRangeGroup; if (columnRangeGroup != null) { for (int num11 = 0; num11 < columnCount; num11++) { int num10; bool flag; columnsInfo.GetRangeGroup(num11, out num10, out flag); columnRangeGroup.Data.SetLevel(baseColumn + num11, num10); columnRangeGroup.Data.SetCollapsed(baseColumn + num11, flag); } } } }
public static void SaveColumnHeaderInfo(Worksheet sheet, CopyMoveCellsInfo headerCellsInfo, CopyMoveColumnsInfo columnsInfo, int baseColumn, CopyToOption option) { int rowCount = headerCellsInfo.RowCount; int columnCount = headerCellsInfo.ColumnCount; for (int i = 0; i < rowCount; i++) { for (int k = 0; k < columnCount; k++) { if ((option & CopyToOption.Value) > ((CopyToOption)0)) { headerCellsInfo.SaveValue(i, k, sheet.GetValue(i, baseColumn + k, SheetArea.ColumnHeader)); } if ((option & CopyToOption.Style) > ((CopyToOption)0)) { headerCellsInfo.SaveStyle(i, k, GetStyleObject(sheet, i, baseColumn + k, SheetArea.ColumnHeader)); } if ((option & CopyToOption.Tag) > ((CopyToOption)0)) { headerCellsInfo.SaveTag(i, k, sheet.GetTag(i, baseColumn + k, SheetArea.ColumnHeader)); } } } if ((option & CopyToOption.Value) > ((CopyToOption)0)) { for (int m = 0; m < columnCount; m++) { if (sheet.IsColumnBound(baseColumn + m)) { columnsInfo.SaveBindingField(m, sheet.GetDataColumnName(baseColumn + m)); } } } if ((option & CopyToOption.Span) > ((CopyToOption)0)) { IEnumerator enumerator = sheet.ColumnHeaderSpanModel.GetEnumerator(0, baseColumn, rowCount, columnCount); while (enumerator.MoveNext()) { headerCellsInfo.SaveSpan((CellRange)enumerator.Current); } } columnCount = columnsInfo.ColumnCount; for (int j = 0; j < columnCount; j++) { columnsInfo.SaveWidth(j, sheet.GetColumnWidth(baseColumn + j)); columnsInfo.SaveVisible(j, sheet.GetColumnVisible(baseColumn + j)); columnsInfo.SaveResizable(j, sheet.GetColumnResizable(baseColumn + j)); columnsInfo.SaveTag(j, sheet.GetTag(-1, baseColumn + j)); } if ((option & CopyToOption.Style) > ((CopyToOption)0)) { for (int n = 0; n < columnCount; n++) { columnsInfo.SaveViewportColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.Cells)); columnsInfo.SaveHeaderColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.ColumnHeader)); } } if ((option & CopyToOption.RangeGroup) > ((CopyToOption)0)) { RangeGroup columnRangeGroup = sheet.ColumnRangeGroup; if ((columnRangeGroup != null) && !columnRangeGroup.IsEmpty()) { for (int num8 = 0; num8 < columnCount; num8++) { columnsInfo.SaveRangeGroup(num8, columnRangeGroup.Data.GetLevel(baseColumn + num8), columnRangeGroup.Data.GetCollapsed(baseColumn + num8)); } } } }
/// <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; }