49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using System.Collections;
|
|
|
|
namespace RhSolutions.ExcelExtensions;
|
|
|
|
public class Columns : IEnumerable<Column>
|
|
{
|
|
public Table ParentTable { get; }
|
|
public int Length
|
|
{
|
|
get => _range.Columns.Count;
|
|
}
|
|
private Column[] _columns;
|
|
private Range _range;
|
|
|
|
public Columns(Table parentTable)
|
|
{
|
|
ParentTable = parentTable;
|
|
_range = parentTable.Range;
|
|
_columns = new Column[Length];
|
|
}
|
|
|
|
public Column this[int index]
|
|
{
|
|
get
|
|
{
|
|
if (index < 0 || index >= Length)
|
|
{
|
|
throw new IndexOutOfRangeException();
|
|
}
|
|
|
|
if (_columns[index] == null)
|
|
{
|
|
_columns[index] = new Column(_range.Columns[index + 1], ParentTable);
|
|
return _columns[index];
|
|
}
|
|
else
|
|
{
|
|
return _columns[index];
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator<Column> GetEnumerator()
|
|
{
|
|
return new ColumnsEnumerator(this);
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
} |