/// <summary> /// Saves undo information. /// </summary> public void SaveState() { double[] numArray = null; bool[] flagArray = null; if (((_sheet != null) && (_columns != null)) && (_columns.Length > 0)) { numArray = new double[_columns.Length]; flagArray = new bool[_columns.Length]; int num = _rowHeader ? _sheet.RowHeader.ColumnCount : _sheet.ColumnCount; for (int i = 0; i < _columns.Length; i++) { ColumnAutoFitExtent extent = _columns[i]; if ((0 <= extent.Column) && (extent.Column < num)) { if (_rowHeader) { numArray[i] = _sheet.GetColumnWidth(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader); flagArray[i] = _sheet.GetColumnVisible(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader); } else { numArray[i] = _sheet.GetColumnWidth(extent.Column, SheetArea.Cells); flagArray[i] = _sheet.GetColumnVisible(extent.Column, SheetArea.Cells); } } else { numArray[i] = -1.0; flagArray[i] = false; } } } _oldSizes = numArray; _oldVisibles = flagArray; }
/// <summary> /// Undoes the column automatic fit action. /// </summary> /// <param name="sender">Object on which the action occurred.</param> /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> public bool Undo(object sender) { bool flag = false; if (((_sheet != null) && (_columns != null)) && (_columns.Length > 0)) { Excel excel = sender as Excel; int[] columnsReiszed = GetColumnsReiszed(_columns); base.SuspendInvalidate(sender); try { if ((excel != null) && excel.RaiseColumnWidthChanging(columnsReiszed, _rowHeader)) { return(true); } int num2 = _rowHeader ? _sheet.RowHeader.ColumnCount : _sheet.ColumnCount; for (int i = 0; i < _columns.Length; i++) { ColumnAutoFitExtent extent = _columns[i]; double width = _oldSizes[i]; bool flag3 = _oldVisibles[i]; if (((0 <= i) && (i < num2)) && (width != -1.0)) { if (_rowHeader && _sheet.GetColumnResizable(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader)) { _sheet.SetColumnWidth(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader, width); _sheet.SetColumnVisible(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader, flag3); flag = true; } else if (_sheet.GetColumnResizable(extent.Column, SheetArea.Cells)) { _sheet.SetColumnWidth(extent.Column, SheetArea.Cells, width); _sheet.SetColumnVisible(extent.Column, SheetArea.Cells, flag3); flag = true; } } } } finally { base.ResumeInvalidate(sender); } if (excel != null) { excel.InvalidateLayout(); excel.InvalidateViewportHorizontalArrangement(-2); excel.InvalidateHeaderHorizontalArrangement(); excel.InvalidateMeasure(); excel.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader); excel.RaiseColumnWidthChanged(columnsReiszed, _rowHeader); } } return(flag); }
/// <summary> /// Performs the column automatic fit action. /// </summary> /// <param name="sender">Object on which the action occurred.</param> public override void Execute(object sender) { if (CanExecute(sender)) { Excel excel = sender as Excel; int[] columnsReiszed = GetColumnsReiszed(_columns); base.SuspendInvalidate(sender); try { if ((excel != null) && excel.RaiseColumnWidthChanging(columnsReiszed, _rowHeader)) { return; } SaveState(); int num = _rowHeader ? _sheet.RowHeader.ColumnCount : _sheet.ColumnCount; for (int i = 0; i < _columns.Length; i++) { ColumnAutoFitExtent extent = _columns[i]; if ((0 <= extent.Column) && (extent.Column < num)) { if (_rowHeader && _sheet.GetColumnResizable(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader)) { double width = Math.Ceiling(excel.GetColumnAutoFitValue(extent.Column, true)); if (width >= 0.0) { width = (width + 1.0) + 4.0; } if (width != _sheet.GetColumnWidth(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader)) { _sheet.SetColumnWidth(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader, width); } _sheet.SetColumnVisible(extent.Column, SheetArea.CornerHeader | SheetArea.RowHeader, true); } else if (_sheet.GetColumnResizable(extent.Column, SheetArea.Cells)) { double num4 = Math.Ceiling(excel.GetColumnAutoFitValue(extent.Column, false)); if (num4 >= 0.0) { num4 = (num4 + 1.0) + 4.0; } if (num4 != _sheet.GetColumnWidth(extent.Column, SheetArea.Cells)) { _sheet.SetColumnWidth(extent.Column, SheetArea.Cells, num4); } _sheet.SetColumnVisible(extent.Column, SheetArea.Cells, true); } } } } finally { base.ResumeInvalidate(sender); } if (excel != null) { excel.InvalidateLayout(); excel.InvalidateViewportHorizontalArrangement(-2); excel.InvalidateHeaderHorizontalArrangement(); excel.InvalidateMeasure(); excel.RefreshRange(-1, -1, -1, -1, SheetArea.Cells | SheetArea.ColumnHeader); excel.RefreshFloatingObjects(); excel.RaiseColumnWidthChanged(columnsReiszed, _rowHeader); } } }