Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

ExcelA1

OfficeIMO.Excel

Namespace
OfficeIMO.Excel
Assembly
OfficeIMO.Excel
Source revision
e163ccb36643 with working tree changes
Source
A1.cs:23
Modifiers
static

Utility helpers for parsing and converting Excel A1 references. Public so examples and consumers can reuse consistent logic without re-implementing regexes or math.

Inheritance

  • object
  • ExcelA1

Methods

public static string CellReference(int row, int column) #

Builds an A1 cell reference from 1-based row and column indexes.

Parameters

row int required
column int required

Returns

string
public static string ColumnIndexToLetters(int index) #

Converts a 1-based column index to Excel column letters (e.g., 1→"A", 27→"AA").

Parameters

index int required
1-based column index.

Returns

string Excel column letters; returns "A" for non-positive inputs.

Examples

string col = ExcelA1.ColumnIndexToLetters(28); // "AB" int idx = ExcelA1.ColumnLettersToIndex("AB"); // 28

public static int ColumnLettersToIndex(string letters) #

Converts column letters (e.g., "A", "AA") to a 1-based column index. Non-letter characters are ignored; returns 0 for empty/invalid input.

Parameters

letters string required
Excel column letters.

Returns

int 1-based column index, or 0 when input yields no letters.
public static ValueTuple<int, int> ParseCellRef(string cellRef) #

Parses a single A1 cell reference (e.g., "B5") into a 1-based (row, column) tuple. Returns (0,0) when the input does not match a valid simple cell reference.

Parameters

cellRef string required
A1 cell reference, without sheet prefix.

Returns

ValueTuple<int, int> Tuple of row and column (1-based). Returns (0,0) if invalid.
public static ValueTuple<int, int, int, int> ParseRange(string a1Range) #

Parses an A1 range (e.g., "A1:B10") into 1-based, normalized bounds. If the bounds are inverted, they are swapped so that r1 <= r2 and c1 <= c2.

Parameters

a1Range string required
A1 range string, without sheet prefix.

Returns

ValueTuple<int, int, int, int> (r1, c1, r2, c2) 1-based coordinates.

Exceptions

  • ArgumentException – Thrown when the input is not a valid A1 range.

Examples

var (r1, c1, r2, c2) = ExcelA1.ParseRange("B2:D10"); // r1=2, c1=2, r2=10, c2=4

public static bool TryParseRange(string a1Range, out int r1, out int c1, out int r2, out int c2) #

Tries to parse an A1 range (e.g., "A1:B10") into 1-based, normalized bounds. Returns false when the input is not a valid A1 range.

Parameters

a1Range string required
r1 int required
c1 int required
r2 int required
c2 int required

Returns

bool

Fields

public const int MaxRows #

Maximum row index supported by the Excel worksheet grid.

Value: 1048576
public const int MaxColumns #

Maximum column index supported by the Excel worksheet grid.

Value: 16384