module

Sheety::CellRefs

Shared A1-style column letter <-> number conversion.

Excel columns use bijective base-26: A=1, Z=26, AA=27, and so on. This conversion previously existed as seven copy-pasted variants across the TUI, the dependency extractor, the runtime helpers baked into generated binaries, and the Excel exporter; they are all defined here now.

Constants

GRID_MAX = 1000

Highest row/column sheety's fixed 1000x1000 grid addresses. Whole-column ranges (A:B) clamp their rows to this.

Class methods

col_to_num(col : String) : Int32

Convert column letter(s) to a 1-based number ("A" -> 1, "AA" -> 27). Input is upcased, so callers may pass either case.

Source
num_to_col(num : Int32) : String

Convert a 1-based number to column letter(s) (1 -> "A", 27 -> "AA"). Returns "" for 0, matching the behavior of every previous copy.

Source
parse_range(range : String) : RangeBounds | Nil

Parse an A1-style range into normalized bounds, or return nil when the range is unsupported.

Accepted forms (any case, with or without $ anchors):

  • "A1:B5" concrete range; reversed bounds (e.g. "B2:A1") are swapped, matching Excel's normalization
  • "A:B" whole-column range, clamped to rows 1..GRID_MAX

Whole-row ranges ("1:10") and anything else return nil; callers treat that as a loud per-formula failure rather than silently computing over an empty set of cells.

Source
parse_ref(ref : String) : NamedTuple(col: Int32, row: Int32) | Nil

Parse a single cell reference ("A1", "$B$2") into 1-based column/row, or nil if it doesn't have that shape.

Source

Nested types