using System; using CPF.ReoGrid.DataFormat; namespace CPF.ReoGrid.Actions { public class SetCellDataAction : BaseWorksheetAction { public int Row { get { return this.row; } set { this.row = value; } } public int Col { get { return this.col; } set { this.col = value; } } public object Data { get { return this.data; } set { this.data = value; } } public SetCellDataAction(int row, int col, object data) { this.row = row; this.col = col; this.data = data; } public SetCellDataAction(CellPosition pos, object data) : this(pos.Row, pos.Col, data) { } public SetCellDataAction(string address, object data) { CellPosition cellPosition = new CellPosition(address); this.row = cellPosition.Row; this.col = cellPosition.Col; this.data = data; } public override void Do() { Cell cell = base.Worksheet.CreateAndGetCell(this.row, this.col); this.backupData = (cell.HasFormula ? ("=" + cell.InnerFormula) : cell.InnerData); this.backupDataFormat = cell.DataFormat; this.backupDataFormatArgs = cell.DataFormatArgs; try { base.Worksheet.SetSingleCellData(cell, this.data); WorksheetSettings worksheetSettings = WorksheetSettings.Edit_AutoExpandRowHeight | WorksheetSettings.Edit_AllowAdjustRowHeight; RowHeader rowHeader = base.Worksheet.GetRowHeader(cell.InternalRow); this.backupRowHeight = new ushort?(rowHeader.InnerHeight); bool flag = (base.Worksheet.settings & worksheetSettings) == worksheetSettings && rowHeader.IsAutoHeight; if (flag) { cell.ExpandRowHeight(); } } catch (Exception ex) { base.Worksheet.NotifyExceptionHappen(ex); } } public override void Redo() { this.Do(); Cell cell = base.Worksheet.GetCell(this.row, this.col); bool flag = cell != null; if (flag) { base.Worksheet.SelectRange(new RangePosition(cell.InternalRow, cell.InternalCol, (int)cell.Rowspan, (int)cell.Colspan)); } } public override void Undo() { bool flag = this.backupRowHeight != null; if (flag) { RowHeader rowHeader = base.Worksheet.GetRowHeader(this.row); int innerHeight = (int)rowHeader.InnerHeight; ushort? num = this.backupRowHeight; int? num2 = (num != null) ? new int?((int)num.GetValueOrDefault()) : null; bool flag2 = !(innerHeight == num2.GetValueOrDefault() & num2 != null); if (flag2) { base.Worksheet.SetRowsHeight(this.row, 1, this.backupRowHeight.Value); } } Cell cell = base.Worksheet.GetCell(this.row, this.col); bool flag3 = cell != null; if (flag3) { cell.DataFormat = this.backupDataFormat; cell.DataFormatArgs = this.backupDataFormatArgs; base.Worksheet.SetSingleCellData(cell, this.backupData); base.Worksheet.SelectRange(new RangePosition(cell.InternalRow, cell.InternalCol, (int)cell.Rowspan, (int)cell.Colspan)); } } public override string GetName() { string text = (this.data == null) ? "null" : this.data.ToString(); return "Set Cell Value: " + ((text.Length > 10) ? (text.Substring(0, 7) + "...") : text); } private int row; private int col; private object data; private object backupData; private CellDataFormatFlag backupDataFormat; private object backupDataFormatArgs; private ushort? backupRowHeight = new ushort?(0); } }