RhSolutions-AddIn/RhSolutions.ExcelExtensions/Column.cs
2023-04-01 15:58:42 +03:00

48 lines
1.0 KiB
C#

using System.Collections;
namespace RhSolutions.ExcelExtensions;
public sealed class Column : Table, IEnumerable<TableCell>
{
public string Header
{
get => Range.Cells[1, 1].Value.ToString();
}
public int Index
{
get => Range.Column - ParentTable.Range.Column;
}
public int Length
{
get => Range.Rows.Count;
}
public Column(Range range, Table table) : base(range, table)
{
Range = range;
ParentTable = table;
}
public TableCell this[int index]
{
get => new(Range.Cells[index + 1, 1], ParentTable);
}
public IEnumerator<TableCell> GetEnumerator()
{
return new ColumnEnumerator(Range, ParentTable);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public Column AddLeft()
{
Range.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
return ParentTable.Columns[this.Index - 1];
}
}