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

55 lines
1010 B
C#

using System.Collections;
namespace RhSolutions.ExcelTable;
public class ExcelColumnEnumerator : IEnumerator<ExcelTableCell>
{
public Range Range { get; }
public ExcelTable ParentTable { get; }
private int position = 0;
object IEnumerator.Current
{
get
{
return Current;
}
}
public ExcelTableCell Current
{
get
{
try
{
return new ExcelTableCell(Range.Cells[position, 1], ParentTable);
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
public ExcelColumnEnumerator(Range range, ExcelTable table)
{
Range = range;
ParentTable = table;
}
public bool MoveNext()
{
position++;
return (position <= Range.Rows.Count);
}
public void Reset()
{
position = 0;
}
public void Dispose()
{
}
}