RhSolutions-AddIn/RhSolutions.ExcelExtensions/Column.cs

48 lines
1.0 KiB
C#
Raw Normal View History

2023-03-31 15:27:31 +03:00
using System.Collections;
2023-04-01 15:58:42 +03:00
namespace RhSolutions.ExcelExtensions;
2023-03-31 15:27:31 +03:00
2023-04-01 15:58:42 +03:00
public sealed class Column : Table, IEnumerable<TableCell>
2023-03-31 15:27:31 +03:00
{
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;
}
2023-04-01 15:58:42 +03:00
public Column(Range range, Table table) : base(range, table)
2023-03-31 15:27:31 +03:00
{
Range = range;
ParentTable = table;
}
2023-04-01 15:58:42 +03:00
public TableCell this[int index]
2023-03-31 15:27:31 +03:00
{
get => new(Range.Cells[index + 1, 1], ParentTable);
}
2023-04-01 15:58:42 +03:00
public IEnumerator<TableCell> GetEnumerator()
2023-03-31 15:27:31 +03:00
{
2023-04-01 15:58:42 +03:00
return new ColumnEnumerator(Range, ParentTable);
2023-03-31 15:27:31 +03:00
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
2023-04-01 15:58:42 +03:00
public Column AddLeft()
2023-03-31 15:27:31 +03:00
{
Range.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
return ParentTable.Columns[this.Index - 1];
}
}