linexcel.refs¶
linexcel.refs ¶
Excel reference utilities: A1 ↔ (row, col), R1C1, ranges.
All conversions are independent of the computation engine so they remain unit-testable.
Rect
dataclass
¶
Cell rectangle (inclusive bounds), with optional sheet.
Source code in src/linexcel/refs.py
clipped ¶
Clip the range to the used dimensions of the sheet.
Source code in src/linexcel/refs.py
intersects ¶
Check if two rectangles overlap.
Rect(None, 1, 1, 3, 3).intersects(Rect(None, 2, 2, 5, 5)) True Rect(None, 1, 1, 2, 2).intersects(Rect(None, 4, 4, 5, 5)) False
Source code in src/linexcel/refs.py
to_a1 ¶
Convert to A1 notation string.
Rect(None, 1, 1, 1, 1).to_a1() 'A1' Rect(None, 1, 1, 3, 3).to_a1() 'A1:C3' Rect("Sheet1", 1, 1, 1, 1).to_a1() 'Sheet1!A1'
Source code in src/linexcel/refs.py
RefDetail
dataclass
¶
Parsed reference with $ anchors (for group stretching).
Source code in src/linexcel/refs.py
col_to_num ¶
Convert a column letter (A, B, ..., XFD) to a 1-indexed number.
col_to_num("A") 1 col_to_num("Z") 26 col_to_num("AA") 27 col_to_num("XFD") 16384
Source code in src/linexcel/refs.py
num_to_col ¶
Convert a 1-indexed column number to letters.
num_to_col(1) 'A' num_to_col(26) 'Z' num_to_col(27) 'AA' num_to_col(16384) 'XFD'
Source code in src/linexcel/refs.py
quote_sheet ¶
Quote a sheet name if necessary for inclusion in a formula.
quote_sheet("Sheet1") 'Sheet1' quote_sheet("Sheet 1") "'Sheet 1'" quote_sheet("L'été") "'L''été'"
Source code in src/linexcel/refs.py
split_sheet_prefix ¶
Split the sheet prefix from a reference ('Sheet 1'!A1 → (Sheet 1, A1)).
split_sheet_prefix("Sheet1!A1") ('Sheet1', 'A1') split_sheet_prefix("'My Sheet'!B2:C3") ('My Sheet', 'B2:C3') split_sheet_prefix("A1") (None, 'A1')
Source code in src/linexcel/refs.py
parse_ref ¶
Parse an A1 reference (cell, range, whole columns or rows).
Returns None if the string is not a valid A1 reference
(defined name, structured table reference, ...).
parse_ref("A1") Rect(sheet=None, r1=1, c1=1, r2=1, c2=1) parse_ref("B3:D5") Rect(sheet=None, r1=3, c1=2, r2=5, c2=4) parse_ref("Sheet1!$C$2") Rect(sheet='Sheet1', r1=2, c1=3, r2=2, c2=3) parse_ref("A:A") is None False parse_ref("not_a_ref") is None True
Source code in src/linexcel/refs.py
normalize_whole_ranges ¶
Replace -1 markers (whole column/row) with max bounds.
Source code in src/linexcel/refs.py
parse_ref_detailed ¶
Like :func:parse_ref, but preserves absolute anchors on each bound.
Source code in src/linexcel/refs.py
stretch_ref ¶
stretch_ref(detail: RefDetail, rep_row: int, rep_col: int, rows_span: tuple[int, int], cols_span: tuple[int, int]) -> Rect
Stretch a representative cell's reference to an entire stretched group.
rows_span/cols_span are the (min, max) bounds of the group's
member cells. Relative bounds follow the displacement, anchored bounds
($) stay fixed.
Source code in src/linexcel/refs.py
cell_to_r1c1 ¶
Convert an A1 cell reference to R1C1 relative to (base_row, base_col).
Source code in src/linexcel/refs.py
ref_to_r1c1 ¶
Convert a full reference (with sheet and ':') to R1C1 form.