Convert between Sheets value grids ([[...], ...], rows of cells)
and records (one Map per row, keyed by the header row), plus A1
notation helpers. All functions are pure.
Sheets drops trailing empty cells and empty trailing rows from responses, so rows may be shorter than the header: missing cells become null in records.
Values
LETTERS
LETTERS: Str "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Functions
a1
fn (sheet-title: Str): Str
fn (sheet-title: Str, range: Str): Str
An A1 range on a sheet: a1("Q3 Plan", "A1:C10") is 'Q3 Plan'!A1:C10; a1("Data") is the whole sheet (Data).
cell-value
fn (value: Any): Any
A record value as a cell: Str, Int, Dec and Bool pass through; null becomes "" (an empty cell); Maps and Vecs become JSON text.
column-letter
fn (index: Int): Str
The A1 letters for a 0-based column index: 0 is A, 25 is Z, 26 is AA, 701 is ZZ.
grid-a1
fn (start-row: Int, start-column: Int, rows: Int, columns: Int): Str
The A1 range covering rows x columns cells from the top-left cell (0-based start-row, start-column): grid-a1(0, 0, 3, 2) is A1:B3.
header-names
fn (header: Vec): Vec
The header row as column names: each cell as a trimmed Str; blank headers become null (their column is skipped).
is-blank-cell
fn (cell: Any): Bool
quote-sheet
fn (title: Str): Str
A sheet title quoted for A1 notation: Sheet1 stays as is; "Q3 Plan" becomes 'Q3 Plan' and a ' inside is doubled.
record-columns
fn (records: Vec): Vec
The column names for records: every key, in order of first appearance.
records-to-grid
fn (records: Vec): Vec
fn (records: Vec, columns: Vec): Vec
Records as a full grid: the header row (columns, default every key) followed by records-to-rows.
records-to-rows
fn (records: Vec): Vec
fn (records: Vec, columns: Vec): Vec
Records as value rows ordered by columns (default: every key in
order of first appearance), without a header. Missing values become
"".
::google::sheets::records/records-to-rows([{name: "Ada", score: 9}], ["name", "score"])
// [["Ada", 9]]
row-to-record
fn (columns: Vec, row: Vec): Map
One row as a Map keyed by columns (from header-names); missing cells are null and null-named columns are skipped.
rows-to-records
fn (values: Vec?): Vec
A value grid whose first row is a header, as a Vec of Maps. Fully
blank rows are skipped. A missing or empty grid gives [].
::google::sheets::records/rows-to-records([["name", "score"], ["Ada", 9], ["Bob"]])
// [{name: "Ada", score: 9}, {name: "Bob", score: null}]