vimsheet.model.range

A1 notation helpers and named-range registry.

vimsheet.model.range.col_letters_to_index(letters)[source]

Convert column letters (A, B, …, ZZ) to a 0-based column index.

>>> col_letters_to_index("A")
0
>>> col_letters_to_index("Z")
25
>>> col_letters_to_index("AA")
26
Parameters:

letters (str)

Return type:

int

vimsheet.model.range.col_index_to_letters(index)[source]

Convert a 0-based column index to column letters.

>>> col_index_to_letters(0)
'A'
>>> col_index_to_letters(25)
'Z'
>>> col_index_to_letters(26)
'AA'
Parameters:

index (int)

Return type:

str

vimsheet.model.range.a1_to_rowcol(address)[source]

Parse an A1-notation address to a (row, col) pair (0-based).

Supports absolute references ($A$1).

>>> a1_to_rowcol("A1")
(0, 0)
>>> a1_to_rowcol("B3")
(2, 1)
>>> a1_to_rowcol("$C$5")
(4, 2)
Parameters:

address (str)

Return type:

tuple[int, int]

vimsheet.model.range.rowcol_to_a1(row, col)[source]

Convert a 0-based (row, col) pair to an A1-notation address.

>>> rowcol_to_a1(0, 0)
'A1'
>>> rowcol_to_a1(2, 1)
'B3'
Parameters:
Return type:

str

class vimsheet.model.range.CellRange(start_row, start_col, end_row, end_col)[source]

Bases: object

A rectangular range identified by its top-left and bottom-right corners (0-based).

Parameters:
  • start_row (int)

  • start_col (int)

  • end_row (int)

  • end_col (int)

start_row: int
start_col: int
end_row: int
end_col: int
classmethod from_a1(range_str)[source]

Parse an A1:B5 range string.

Also accepts single-cell addresses like “A1”.

Parameters:

range_str (str)

Return type:

CellRange

to_a1()[source]

Return the canonical A1:B5 string.

Return type:

str

property num_rows: int

Number of rows in the range.

property num_cols: int

Number of columns in the range.

iter_cells()[source]

Yield every (row, col) pair in the range, row-major order.

Return type:

Iterator[tuple[int, int]]

contains(row, col)[source]

Return True if (row, col) is inside this range.

Parameters:
Return type:

bool

__init__(start_row, start_col, end_row, end_col)
Parameters:
  • start_row (int)

  • start_col (int)

  • end_row (int)

  • end_col (int)

Return type:

None

class vimsheet.model.range.NamedRangeRegistry(_names=<factory>)[source]

Bases: object

Stores name → range-string mappings for a single sheet or workbook.

Parameters:

_names (dict[str, str])

define(name, range_str)[source]

Define or update a named range.

Parameters:
Return type:

None

delete(name)[source]

Remove a named range. Raises KeyError if not found.

Parameters:

name (str)

Return type:

None

resolve(name)[source]

Return the range string for name, or None if undefined.

Parameters:

name (str)

Return type:

str | None

all_names()[source]

Return sorted list of all defined names.

Return type:

list[str]

__init__(_names=<factory>)
Parameters:

_names (dict[str, str])

Return type:

None