RhSolutions-AddIn/RhSolutions.AddIn/ExcelTable/ExcelColumn.cs
2023-03-31 15:27:31 +03:00

48 lines
1.1 KiB
C#

using System.Collections;
namespace RhSolutions.ExcelTable;
public sealed class ExcelColumn : ExcelTable, IEnumerable<ExcelTableCell>
{
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 ExcelColumn(Range range, ExcelTable table) : base(range, table)
{
Range = range;
ParentTable = table;
}
public ExcelTableCell this[int index]
{
get => new(Range.Cells[index + 1, 1], ParentTable);
}
public IEnumerator<ExcelTableCell> GetEnumerator()
{
return new ExcelColumnEnumerator(Range, ParentTable);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public ExcelColumn AddLeft()
{
Range.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
return ParentTable.Columns[this.Index - 1];
}
}