From 448af8ecd7bf9db070e090c4b434da693ba0ae89 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sat, 1 Apr 2023 15:58:42 +0300 Subject: Move Excel extensions to own project --- RhSolutions.ExcelExtensions/Table.cs | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 RhSolutions.ExcelExtensions/Table.cs (limited to 'RhSolutions.ExcelExtensions/Table.cs') diff --git a/RhSolutions.ExcelExtensions/Table.cs b/RhSolutions.ExcelExtensions/Table.cs new file mode 100644 index 0000000..a19a4b4 --- /dev/null +++ b/RhSolutions.ExcelExtensions/Table.cs @@ -0,0 +1,53 @@ +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 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; + } + } + } +} -- cgit v1.2.3