61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace CPF.ReoGrid.Actions
|
|
{
|
|
public class SetColumnsWidthAction : WorksheetReusableAction
|
|
{
|
|
public ushort Width
|
|
{
|
|
get
|
|
{
|
|
return this.width;
|
|
}
|
|
set
|
|
{
|
|
this.width = value;
|
|
}
|
|
}
|
|
|
|
public SetColumnsWidthAction(int col, int count, ushort width) : base(new RangePosition(0, col, -1, count))
|
|
{
|
|
this.width = width;
|
|
}
|
|
|
|
public override void Do()
|
|
{
|
|
int col = base.Range.Col;
|
|
int cols = base.Range.Cols;
|
|
this.backupCols.Clear();
|
|
int num = col + cols;
|
|
for (int i = col; i < num; i++)
|
|
{
|
|
ColumnHeader columnHeader = base.Worksheet.RetrieveColumnHeader(i);
|
|
this.backupCols.Add(i, columnHeader.InnerWidth);
|
|
}
|
|
base.Worksheet.SetColumnsWidth(col, cols, this.width);
|
|
}
|
|
|
|
public override void Undo()
|
|
{
|
|
int col = base.Range.Col;
|
|
int cols = base.Range.Cols;
|
|
base.Worksheet.SetColumnsWidth(col, cols, (int c) => (int)this.backupCols[c], true, true);
|
|
}
|
|
|
|
public override string GetName()
|
|
{
|
|
return "Set Cols Width: " + this.width.ToString();
|
|
}
|
|
|
|
public override WorksheetReusableAction Clone(RangePosition range)
|
|
{
|
|
return new SetColumnsWidthAction(range.Col, range.Cols, this.width);
|
|
}
|
|
|
|
private ushort width;
|
|
|
|
private Dictionary<int, ushort> backupCols = new Dictionary<int, ushort>();
|
|
}
|
|
}
|