RhSolutions-AddIn/RhSolutions.ExcelExtensions/Rows.cs

40 lines
826 B
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 class Rows : IEnumerable<Row>
2023-03-31 15:27:31 +03:00
{
public Range Range { get; }
2023-04-01 15:58:42 +03:00
public Table ParentTable { get; }
2023-03-31 15:27:31 +03:00
public int Length
{
get => Range.Rows.Count;
}
2023-04-01 15:58:42 +03:00
public Rows(Range range, Table parentTable)
2023-03-31 15:27:31 +03:00
{
Range = range;
ParentTable = parentTable;
}
2023-04-01 15:58:42 +03:00
public Row this[int index]
2023-03-31 15:27:31 +03:00
{
get
{
if (index < 0 || index + 1 > Range.Rows.Count)
{
throw new IndexOutOfRangeException();
}
2023-04-01 15:58:42 +03:00
return new Row(Range.Rows[index + 1], ParentTable);
2023-03-31 15:27:31 +03:00
}
}
2023-04-01 15:58:42 +03:00
public IEnumerator<Row> GetEnumerator()
2023-03-31 15:27:31 +03:00
{
2023-04-01 15:58:42 +03:00
return new RowsEnumerator(Range, ParentTable);
2023-03-31 15:27:31 +03:00
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}