diff options
Diffstat (limited to 'RhSolutions.ExcelExtensions/Column.cs')
-rw-r--r-- | RhSolutions.ExcelExtensions/Column.cs | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/RhSolutions.ExcelExtensions/Column.cs b/RhSolutions.ExcelExtensions/Column.cs index 53a1f3d..341897c 100644 --- a/RhSolutions.ExcelExtensions/Column.cs +++ b/RhSolutions.ExcelExtensions/Column.cs @@ -1,44 +1,62 @@ -using System.Collections; +namespace RhSolutions.ExcelExtensions; -namespace RhSolutions.ExcelExtensions; - -public sealed class Column : Table, IEnumerable<TableCell> +public sealed class Column { + public Table ParentTable { get; } public string Header { - get => Range.Cells[1, 1].Value.ToString(); + get => _range.Cells[1, 1].Value2.ToString() ?? String.Empty; } public int Index { - get => Range.Column - ParentTable.Range.Column; + get => _range.Column - ParentTable.Range.Column; } public int Length { - get => Range.Rows.Count; - } - - public Column(Range range, Table table) : base(range, table) - { - Range = range; - ParentTable = table; + get => _range.Rows.Count; } + private Cell[] _cells; + private readonly Range _range; - public TableCell this[int index] + public Column(Range range, Table table) { - get => new(Range.Cells[index + 1, 1], ParentTable); + _cells = new Cell[range.Rows.Count]; + _range = range; + ParentTable = table ?? + throw new ArgumentNullException("table"); } - public IEnumerator<TableCell> GetEnumerator() + public Cell this[int index] { - return new ColumnEnumerator(Range, ParentTable); + get + { + if (_cells[index] == null) + { + _cells[index] = new Cell(_range.Cells[index + 1, 1], ParentTable); + return _cells[index]; + } + else + { + return _cells[index]; + } + } + set + { + if (_cells[index] == null) + { + _cells[index] = new Cell(_range.Cells[index + 1, 1], ParentTable); + _cells[index].Value = value; + } + else + { + _cells[index].Value = value; + } + } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - public Column AddLeft() { - Range.EntireColumn + _range.EntireColumn .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); |