-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathCellRange.cs
More file actions
49 lines (42 loc) · 1.67 KB
/
Copy pathCellRange.cs
File metadata and controls
49 lines (42 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using ExcelDataReader.Core;
namespace ExcelDataReader;
/// <summary>
/// A range for cells using 0 index positions.
/// </summary>
/// <param name="FromColumn">The column the range starts in.</param>
/// <param name="FromRow">The row the range starts in.</param>
/// <param name="ToColumn">The column the range ends in.</param>
/// <param name="ToRow">The row the range ends in.</param>
public sealed record CellRange(int FromColumn, int FromRow, int ToColumn, int ToRow)
{
/// <inheritsdoc/>
public override string ToString() => $"{FromRow}, {ToRow}, {FromColumn}, {ToColumn}";
#if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
internal static CellRange Parse(string range)
{
int index = range.IndexOf(':');
if (index >= 0 && range.IndexOf(':', index + 1) < 0)
{
ReadOnlySpan<char> span = range;
ReferenceHelper.ParseReference(span[..index], out int fromColumn, out int fromRow);
ReferenceHelper.ParseReference(span[(index + 1)..], out int toColumn, out int toRow);
// 0 indexed vs 1 indexed
return new(fromColumn - 1, fromRow - 1, toColumn - 1, toRow - 1);
}
return new(0, 0, 0, 0);
}
#else
internal static CellRange Parse(string range)
{
var fromTo = range.Split(':');
if (fromTo.Length == 2)
{
ReferenceHelper.ParseReference(fromTo[0], out int fromColumn, out int fromRow);
ReferenceHelper.ParseReference(fromTo[1], out int toColumn, out int toRow);
// 0 indexed vs 1 indexed
return new(fromColumn - 1, fromRow - 1, toColumn - 1, toRow - 1);
}
return new(0, 0, 0, 0);
}
#endif
}