RhSolutions-AddIn/RhSolutions.ExcelExtensions/Table.cs
2023-04-01 15:58:42 +03:00

54 lines
1.2 KiB
C#

namespace RhSolutions.ExcelExtensions;
public class Table
{
public Range Range { get; protected set; }
public Table ParentTable { get; protected set; }
public Rows Rows { get; }
public Columns Columns { get; }
public Table(Range range)
{
Range = range;
ParentTable = null;
Rows = new Rows(Range, this);
Columns = new Columns(Range, this);
}
public Table(Range range, Table table)
{
Range = range;
ParentTable = table;
Rows = new Rows(Range, this);
Columns = new Columns(Range, this);
}
public TableCell this[int row, int column]
{
get => new(Range.Cells[row + 1, column + 1], this);
}
public IEnumerable<TableCell> Find(object item)
{
Range firstFound = Range.Find(item);
if (firstFound == null)
{
yield break;
}
Range nextFound = firstFound;
while (true)
{
yield return new TableCell(nextFound, ParentTable ?? this);
nextFound = Range.FindNext(nextFound);
if (nextFound.Row == firstFound.Row
&& nextFound.Column == firstFound.Column)
{
yield break;
}
}
}
}