/** * xlsx FORMULAS — AST → canonical text serializer. * * OWNERSHIP: FORMULA agent (see ast.ts header). * * Canonical form (normative): * - No leading '='. * - No whitespace except inside string literals, sheet names, and * structured-reference column names (the intersection operator * serializes as exactly one space). * - Sheet names quoted exactly when Excel requires it: anything outside * letters/digits/`_`/`.`/non-ASCII, a leading digit, a name that could * read as an A1 or R1C1 cell ref, or TRUE/FALSE; embedded quotes * doubled. For 3-D spans the whole `Start:End` is quoted when either * endpoint needs it. * - Function names uppercase. By default names are CLEAN (`XLOOKUP`, as * the formula bar shows them); with `xlfn: true` names in * {@link XLFN_FUNCTIONS} get their storage prefix back (`_xlfn.XLOOKUP`, * `_xlfn._xlws.SORT`) exactly as Excel writes them into worksheet XML. * - Structured references serialize in Excel's storage form: simple * `Table1[Col]` when the column needs no bracketing (no leading or * trailing space, none of `[ ] ' # @ , :`), `Table1[[My Col ]]` when it * does, single items as `Table1[#All]`, and the full bracketed list for * items + columns / spans (`Table1[[#This Row],[Qty]]`, * `Table1[[A]:[B]]`); `[@]` for a bare this-row ref. Specials inside * column names are escaped with a leading `'`. * - Numbers via shortest round-trip decimal (String(n), exponent * marker uppercased: 1E+21). * - Parentheses appear exactly where the AST has GroupNodes — the * serializer trusts the tree and never invents or drops grouping, so * parse → serialize round-trips the source text character-for-character * (for canonical-form input). */ import { type CellAddress } from '../internal.js'; import { type FormulaNode } from './ast.js'; /** Options for {@link formulaToText}. */ export interface FormulaTextOptions { /** Output reference style. Default 'A1'. */ readonly style?: 'A1' | 'R1C1'; /** * The cell the formula belongs to — required to derive relative R1C1 * offsets ('D2' or {row, col}). Default A1. Ignored for style 'A1'. */ readonly anchor?: string | CellAddress; /** * Emit storage-form function names: names in {@link XLFN_FUNCTIONS} get * the `_xlfn.` (and, for SORT/FILTER, `_xlfn._xlws.`) prefix back, * exactly as Excel stores them in worksheet XML. Default false — * user-facing text with clean names, matching what Excel's formula bar * shows. `setFormula` writes with `xlfn: true`. */ readonly xlfn?: boolean; } /** * Serialize an AST back to canonical formula text (no leading '='). * * Law (tested): `formulaToText(parseFormula(t)) === t` for any `t` * already in canonical A1 form (with `xlfn: true`, the same holds for * Excel's stored form incl. `_xlfn.` prefixes); and for any AST `a`, * `parseFormula(formulaToText(a))` is deep-equal to `a`. * * ```ts * formulaToText(parseFormula('=sum(a1:b2)')) // → 'SUM(A1:B2)' * ``` */ export declare function formulaToText(node: FormulaNode, options?: FormulaTextOptions): string; //# sourceMappingURL=serializer.d.ts.map