RhSolutions-AddIn/RhSolutions.ExcelExtensions/Row.cs

55 lines
1.2 KiB
C#
Raw Normal View History

2023-04-06 08:29:39 +03:00
namespace RhSolutions.ExcelExtensions;
2023-03-31 15:27:31 +03:00
2023-04-06 08:29:39 +03:00
public sealed class Row
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
public Table ParentTable { get; }
2023-03-31 15:27:31 +03:00
public int Index
{
2023-04-06 08:29:39 +03:00
get => _range.Row - ParentTable.Range.Row;
2023-03-31 15:27:31 +03:00
}
public int Length
{
2023-04-06 08:29:39 +03:00
get => _range.Columns.Count;
2023-03-31 15:27:31 +03:00
}
2023-04-06 08:29:39 +03:00
private readonly Cell[] _cells;
private readonly Range _range;
2023-03-31 15:27:31 +03:00
2023-04-06 08:29:39 +03:00
public Row(Range range, Table table)
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
_cells = new Cell[range.Columns.Count];
_range = range;
ParentTable = table ??
throw new ArgumentNullException("table");
2023-03-31 15:27:31 +03:00
}
2023-04-06 08:29:39 +03:00
public Cell this[int index]
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
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];
}
}
2023-03-31 15:27:31 +03:00
}
2023-04-06 08:29:39 +03:00
public Cell this[string header]
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
get
{
int columnIndex = ParentTable.ColumnByHeader(header).Index;
return this[columnIndex];
}
2023-03-31 15:27:31 +03:00
}
}