Page cover image

Inclusive2DRange

A helper class when dealing with a range of data or cells

Instantiate

To create a new range, supply two initial values:

var ir = new Inclusive2DRange("A3", "C1");
Console.WriteLine($"{ir.CorrectedA}:{ir.CorrectedB}{Environment.NewLine}|{ir.MinX_ZeroBased}  -->  {ir.MaxX_ZeroBased}|{Environment.NewLine}|{ir.MinY_ZeroBased}{Environment.NewLine}|{Environment.NewLine}|{ir.MaxY_ZeroBased}");

/* Prints
A1:C3
|0  -->  2|
|0
|
|2
*/
  • As you can see it corrected the range by fixing the starting point to A1, and the ending point to C3.

  • The zero based indexes of the range are 0 to 2 inclusive

You can also convert the common Excel locators using the built in functions:

Console.WriteLine($"1 is {ir.GetExcelColumnName(1)}, 27 is {ir.GetExcelColumnName(27)}");
Console.WriteLine($"A is {ir.GetExcelColumnNumberFromName("A")}, AA is {ir.GetExcelColumnNumberFromName("AA")}");

/* Prints
1 is A, 27 is AA
A is 1, AA is 27
*/

Last updated