RhSolutions-AddIn/RhSolutions.AddIn/ExcelTable/ExcelTable.cs
2023-03-31 15:27:31 +03:00

54 lines
1.3 KiB
C#

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