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

39 lines
895 B
C#

using System.Collections;
namespace RhSolutions.ExcelTable;
public class ExcelColumns : IEnumerable<ExcelColumn>
{
public Range Range { get; }
public ExcelTable ParentTable { get; }
public int Length
{
get => Range.Columns.Count;
}
public ExcelColumns(Range range, ExcelTable parentTable)
{
Range = range;
ParentTable = parentTable;
}
public ExcelColumn this[int index]
{
get
{
if (index < 0 || index + 1 > Range.Columns.Count)
{
throw new IndexOutOfRangeException();
}
return new ExcelColumn(Range.Columns[index + 1], ParentTable);
}
}
public IEnumerator<ExcelColumn> GetEnumerator()
{
return new ExcelColumnsEnumerator(Range, ParentTable);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}