RhSolutions-AddIn/RhSolutions.AddIn/ExcelTable/ExcelColumns.cs

39 lines
895 B
C#
Raw Normal View History

2023-03-31 15:27:31 +03:00
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();
}