Delete Excel.Extensions

This commit is contained in:
Sergey Chebotar 2023-04-07 09:26:52 +03:00
parent 6acba1a542
commit 3f4d7f45b7
10 changed files with 0 additions and 424 deletions

View File

@ -1,26 +0,0 @@
namespace RhSolutions.ExcelExtensions;
public sealed class Cell
{
public Table ParentTable { get; }
public Row ParentRow
{
get => ParentTable.Rows[ParentTable.Range.Row - _range.Row];
}
public Column ParentColumn
{
get => ParentTable.Columns[ParentTable.Range.Column - _range.Column];
}
public object Value
{
get => _range.Cells[1, 1].Value2;
set => _range.Cells[1, 1].Value2 = value;
}
private Range _range;
public Cell(Range range, Table table)
{
_range = range;
ParentTable = table;
}
}

View File

@ -1,65 +0,0 @@
namespace RhSolutions.ExcelExtensions;
public sealed class Column
{
public Table ParentTable { get; }
public string Header
{
get => _range.Cells[1, 1].Value2.ToString() ?? String.Empty;
}
public int Index
{
get => _range.Column - ParentTable.Range.Column;
}
public int Length
{
get => _range.Rows.Count;
}
private Cell[] _cells;
private readonly Range _range;
public Column(Range range, Table table)
{
_cells = new Cell[range.Rows.Count];
_range = range;
ParentTable = table ??
throw new ArgumentNullException("table");
}
public Cell this[int index]
{
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;
}
}
}
public Column AddLeft()
{
_range.EntireColumn
.Insert(XlInsertShiftDirection.xlShiftToRight,
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
return ParentTable.Columns[this.Index - 1];
}
}

View File

@ -1,49 +0,0 @@
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();
}

View File

@ -1,52 +0,0 @@
using System.Collections;
namespace RhSolutions.ExcelExtensions;
public class ColumnsEnumerator: IEnumerator<Column>
{
private Columns _columns;
private int position = -1;
object IEnumerator.Current
{
get
{
return Current;
}
}
public Column Current
{
get
{
try
{
return _columns[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
public ColumnsEnumerator(Columns columns)
{
_columns = columns;
}
public bool MoveNext()
{
position++;
return (position < _columns.Length);
}
public void Reset()
{
position = -1;
}
public void Dispose()
{
}
}

View File

@ -1,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0-windows7.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project>

View File

@ -1,54 +0,0 @@
namespace RhSolutions.ExcelExtensions;
public sealed class Row
{
public Table ParentTable { get; }
public int Index
{
get => _range.Row - ParentTable.Range.Row;
}
public int Length
{
get => _range.Columns.Count;
}
private readonly Cell[] _cells;
private readonly Range _range;
public Row(Range range, Table table)
{
_cells = new Cell[range.Columns.Count];
_range = range;
ParentTable = table ??
throw new ArgumentNullException("table");
}
public Cell this[int index]
{
get
{
if (index < 0 || index >= Length)
{
throw new IndexOutOfRangeException();
}
if (_cells[index] == null)
{
_cells[index] = new Cell(_range.Cells[1, index + 1], ParentTable);
return _cells[index];
}
else
{
return _cells[index];
}
}
}
public Cell this[string header]
{
get
{
int columnIndex = ParentTable.ColumnByHeader(header).Index;
return this[columnIndex];
}
}
}

View File

@ -1,44 +0,0 @@
using System.Collections;
namespace RhSolutions.ExcelExtensions;
public class Rows : IEnumerable<Row>
{
public Table ParentTable { get; }
public int Length
{
get => _range.Rows.Count;
}
private Row[] _rows;
private Range _range;
public Rows(Table parentTable)
{
ParentTable = parentTable;
_range = parentTable.Range;
_rows = new Row[Length];
}
public Row this[int index]
{
get
{
if (_rows[index] == null)
{
_rows[index] = new Row(_range.Rows[index + 1], ParentTable);
return _rows[index];
}
else
{
return _rows[index];
}
}
}
public IEnumerator<Row> GetEnumerator()
{
return new RowsEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

View File

@ -1,52 +0,0 @@
using System.Collections;
namespace RhSolutions.ExcelExtensions;
public class RowsEnumerator : IEnumerator<Row>
{
private Rows _rows;
private int position = -1;
object IEnumerator.Current
{
get
{
return Current;
}
}
public Row Current
{
get
{
try
{
return _rows[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
public RowsEnumerator(Rows rows)
{
_rows = rows;
}
public bool MoveNext()
{
position++;
return (position < _rows.Length);
}
public void Reset()
{
position = -1;
}
public void Dispose()
{
}
}

View File

@ -1,64 +0,0 @@
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; }
private Dictionary<string, Column> _columnsByHeader;
public Table(Range range)
{
Range = range;
ParentTable = this;
Rows = new Rows(this);
Columns = new Columns(this);
_columnsByHeader = new();
foreach(var column in Columns)
{
if (_columnsByHeader.ContainsKey(column.Header))
{
throw new ArgumentException($"Заголовок столбца {column.Header} не уникален");
}
else
{
_columnsByHeader.Add(column.Header, column);
}
}
}
public Column ColumnByHeader(string header)
{
return _columnsByHeader[header];
}
public Cell this[int row, int column]
{
get => this.Rows[row][column];
}
public IEnumerable<Cell> Search(object item)
{
Range firstFound = Range.Find(item);
if (firstFound == null)
{
yield break;
}
Range nextFound = firstFound;
while (true)
{
yield return this[nextFound.Row - ParentTable.Range.Row, nextFound.Column - ParentTable.Range.Column];
nextFound = Range.FindNext(nextFound);
if (nextFound.Row == firstFound.Row
&& nextFound.Column == firstFound.Column)
{
yield break;
}
}
}
}

View File

@ -1,3 +0,0 @@
global using Microsoft.Office.Interop.Excel;
global using System.Collections.Generic;
global using Range = Microsoft.Office.Interop.Excel.Range;