RhSolutions-AddIn/RhSolutions.ExcelExtensions/Row.cs
2023-04-06 08:29:39 +03:00

55 lines
1.2 KiB
C#

namespace RhSolutions.ExcelExtensions;
public sealed class Row
{
public Table ParentTable { get; }
public int Index
{
get => _range.Row - ParentTable.Range.Row;
}
public int Length
{
get => _range.Columns.Count;
}
private readonly Cell[] _cells;
private readonly Range _range;
public Row(Range range, Table table)
{
_cells = new Cell[range.Columns.Count];
_range = range;
ParentTable = table ??
throw new ArgumentNullException("table");
}
public Cell this[int index]
{
get
{
if (index < 0 || index >= Length)
{
throw new IndexOutOfRangeException();
}
if (_cells[index] == null)
{
_cells[index] = new Cell(_range.Cells[1, index + 1], ParentTable);
return _cells[index];
}
else
{
return _cells[index];
}
}
}
public Cell this[string header]
{
get
{
int columnIndex = ParentTable.ColumnByHeader(header).Index;
return this[columnIndex];
}
}
}