|
|
|
@@ -212,20 +212,63 @@ internal sealed class ExcelSheet : ISheet
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IRange RangeByIndexes(uint startRow, uint startCol, uint endRow, uint endCol)
|
|
|
|
public IRange RangeByIndexes(uint startRow, uint startCol, uint endRow, uint endCol)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new ExcelRange(Book, this, startRow, startCol, endRow, endCol);
|
|
|
|
if (startRow == 0) throw new ArgumentException("startRow must be >= 1", nameof(startRow));
|
|
|
|
|
|
|
|
if (startCol == 0) throw new ArgumentException("startCol must be >= 1", nameof(startCol));
|
|
|
|
|
|
|
|
if (endRow == 0) throw new ArgumentException("endRow must be >= 1", nameof(endRow));
|
|
|
|
|
|
|
|
if (endCol == 0) throw new ArgumentException("endCol must be >= 1", nameof(endCol));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Приводим к корректному порядку (пользователь мог передать start > end)
|
|
|
|
|
|
|
|
uint rowStart = Math.Min(startRow, endRow);
|
|
|
|
|
|
|
|
uint rowEnd = Math.Max(startRow, endRow);
|
|
|
|
|
|
|
|
uint colStart = Math.Min(startCol, endCol);
|
|
|
|
|
|
|
|
uint colEnd = Math.Max(startCol, endCol);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ExcelRange(Book, this, rowStart, colStart, rowEnd, colEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IRange RangeByIndexes(uint startRow, string startCol, uint endRow, string endCol)
|
|
|
|
public IRange RangeByIndexes(uint startRow, string startCol, uint endRow, string endCol)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(startCol)) throw new ArgumentException("startCol cannot be null or empty", nameof(startCol));
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(endCol)) throw new ArgumentException("endCol cannot be null or empty", nameof(endCol));
|
|
|
|
|
|
|
|
|
|
|
|
uint startColIdx = CellAddressHelper.ColumnLetterToIndex(startCol);
|
|
|
|
uint startColIdx = CellAddressHelper.ColumnLetterToIndex(startCol);
|
|
|
|
uint endColIdx = CellAddressHelper.ColumnLetterToIndex(endCol);
|
|
|
|
uint endColIdx = CellAddressHelper.ColumnLetterToIndex(endCol);
|
|
|
|
return new ExcelRange(Book, this, startRow, startColIdx, endRow, endColIdx);
|
|
|
|
if (startColIdx == 0) throw new ArgumentException($"Invalid column letter: '{startCol}'", nameof(startCol));
|
|
|
|
|
|
|
|
if (endColIdx == 0) throw new ArgumentException($"Invalid column letter: '{endCol}'", nameof(endCol));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return RangeByIndexes(startRow, startColIdx, endRow, endColIdx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public IRange RangeByLength(uint startRow, uint startCol, uint rows, uint cols)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (startRow == 0) throw new ArgumentException("startRow must be >= 1", nameof(startRow));
|
|
|
|
|
|
|
|
if (startCol == 0) throw new ArgumentException("startCol must be >= 1", nameof(startCol));
|
|
|
|
|
|
|
|
if (rows == 0) throw new ArgumentException("rows must be > 0", nameof(rows));
|
|
|
|
|
|
|
|
if (cols == 0) throw new ArgumentException("cols must be > 0", nameof(cols));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checked
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint endRow = startRow + rows - 1;
|
|
|
|
|
|
|
|
uint endCol = startCol + cols - 1;
|
|
|
|
|
|
|
|
return new ExcelRange(Book, this, startRow, startCol, endRow, endCol);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public IRange RangeByLength(uint startRow, string startCol, uint rows, uint cols)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(startCol)) throw new ArgumentException("startCol cannot be null or empty", nameof(startCol));
|
|
|
|
|
|
|
|
uint startColIdx = CellAddressHelper.ColumnLetterToIndex(startCol);
|
|
|
|
|
|
|
|
if (startColIdx == 0) throw new ArgumentException($"Invalid column letter: '{startCol}'", nameof(startCol));
|
|
|
|
|
|
|
|
return RangeByLength(startRow, startColIdx, rows, cols);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public ISheet RangeByIndexes(uint startRow, uint startCol, uint endRow, uint endCol, Action<IRange> edit)
|
|
|
|
public ISheet RangeByIndexes(uint startRow, uint startCol, uint endRow, uint endCol, Action<IRange> edit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (edit is null) throw new ArgumentNullException(nameof(edit));
|
|
|
|
var range = RangeByIndexes(startRow, startCol, endRow, endCol);
|
|
|
|
var range = RangeByIndexes(startRow, startCol, endRow, endCol);
|
|
|
|
edit(range);
|
|
|
|
edit(range);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
@@ -234,31 +277,16 @@ internal sealed class ExcelSheet : ISheet
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public ISheet RangeByIndexes(uint startRow, string startCol, uint endRow, string endCol, Action<IRange> edit)
|
|
|
|
public ISheet RangeByIndexes(uint startRow, string startCol, uint endRow, string endCol, Action<IRange> edit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (edit is null) throw new ArgumentNullException(nameof(edit));
|
|
|
|
var range = RangeByIndexes(startRow, startCol, endRow, endCol);
|
|
|
|
var range = RangeByIndexes(startRow, startCol, endRow, endCol);
|
|
|
|
edit(range);
|
|
|
|
edit(range);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public IRange RangeByLength(uint startRow, uint startCol, uint rows, uint cols)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (rows == 0 || cols == 0)
|
|
|
|
|
|
|
|
throw new ArgumentException("Rows and columns must be greater than 0");
|
|
|
|
|
|
|
|
uint endRow = startRow + rows - 1;
|
|
|
|
|
|
|
|
uint endCol = startCol + cols - 1;
|
|
|
|
|
|
|
|
return new ExcelRange(Book, this, startRow, startCol, endRow, endCol);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public IRange RangeByLength(uint startRow, string startCol, uint rows, uint cols)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint startColIdx = CellAddressHelper.ColumnLetterToIndex(startCol);
|
|
|
|
|
|
|
|
return RangeByLength(startRow, startColIdx, rows, cols);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public ISheet RangeByLength(uint startRow, uint startCol, uint rows, uint cols, Action<IRange> edit)
|
|
|
|
public ISheet RangeByLength(uint startRow, uint startCol, uint rows, uint cols, Action<IRange> edit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (edit is null) throw new ArgumentNullException(nameof(edit));
|
|
|
|
var range = RangeByLength(startRow, startCol, rows, cols);
|
|
|
|
var range = RangeByLength(startRow, startCol, rows, cols);
|
|
|
|
edit(range);
|
|
|
|
edit(range);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
@@ -267,6 +295,7 @@ internal sealed class ExcelSheet : ISheet
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public ISheet RangeByLength(uint startRow, string startCol, uint rows, uint cols, Action<IRange> edit)
|
|
|
|
public ISheet RangeByLength(uint startRow, string startCol, uint rows, uint cols, Action<IRange> edit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (edit is null) throw new ArgumentNullException(nameof(edit));
|
|
|
|
var range = RangeByLength(startRow, startCol, rows, cols);
|
|
|
|
var range = RangeByLength(startRow, startCol, rows, cols);
|
|
|
|
edit(range);
|
|
|
|
edit(range);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
@@ -274,4 +303,27 @@ internal sealed class ExcelSheet : ISheet
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Merge Operations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public bool TryMergeByIndexes(uint startRow, uint startCol, uint endRow, uint endCol) =>
|
|
|
|
|
|
|
|
RangeByIndexes(startRow, startCol, endRow, endCol).TryMerge();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public bool TryMergeByIndexes(uint startRow, string startCol, uint endRow, string endCol) =>
|
|
|
|
|
|
|
|
RangeByIndexes(startRow, startCol, endRow, endCol).TryMerge();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public bool TryMergeByLength(uint startRow, uint startCol, uint rows, uint cols) =>
|
|
|
|
|
|
|
|
RangeByLength(startRow, startCol, rows, cols).TryMerge();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
|
|
public bool TryMergeByLength(uint startRow, string startCol, uint rows, uint cols) =>
|
|
|
|
|
|
|
|
RangeByLength(startRow, startCol, rows, cols).TryMerge();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|