import type { FormulaAstNode, FormulaColumnSelector, FormulaRangeRefNode, FormulaRowSelector } from "./formulaAst.js"; import type { FormulaErrorCode } from "./formulaErrors.js"; /** * Excel's built-in error sentinels — the set `@mui/x-internal-exceljs-fork` * accepts as a formula `result`. The engine's own `FormulaErrorCode`s are mapped * onto these by `mapFormulaErrorCodeToExcel`. */ export type ExcelFormulaErrorCode = '#N/A' | '#REF!' | '#NAME?' | '#DIV/0!' | '#NULL!' | '#VALUE!' | '#NUM!'; /** * Resolves a canonical reference axis to a coordinate in the *exported* sheet. * `null` means the referenced column/row is not part of the export, so the * converter bakes Excel's `#REF!` token into the formula at that position. */ export interface FormulaExcelSerializeContext { resolveColumn: (selector: FormulaColumnSelector) => { letter: string; absolute: boolean; } | null; resolveRow: (selector: FormulaRowSelector) => { number: number; absolute: boolean; } | null; /** * Resolves a `RANGE_REF` window to its clipped, normalized corner coordinates * in the exported sheet. `null` when any corner falls outside the export — * the converter bakes `#REF!` in place, like a single ref to a missing row. * (`$` markers come from the node's `fixed` flags, not from this resolver.) * @param {FormulaRangeRefNode} node The window to resolve. * @returns {object | null} The corner coordinates, or `null` when unexportable. */ resolveRangeWindow: (node: FormulaRangeRefNode) => { startLetter: string; startNumber: number; endLetter: string; endNumber: number; } | null; /** 1-based Excel row of the cell that owns the formula (for same-row `fieldRef`). */ ownerRowNumber: number; /** 1-based Excel row bounds of the exported data area (for whole-column `columnValues`). */ firstDataRowNumber: number; lastDataRowNumber: number; } export interface FormulaExcelSerializeResult { /** Excel formula string, without the leading `=`. */ formula: string; /** `true` when a reference fell outside the export and `#REF!` was baked in. */ hasRefError: boolean; } /** * Converts a canonical formula AST to an Excel A1 formula string (without the * leading `=`), re-anchoring every reference to its coordinate in the *exported* * sheet via `context`. References to cells outside the export bake Excel's * `#REF!` token in place and set `hasRefError`. Pure: engine types only. * * Mirrors the grid's relative/absolute distinction: stable selectors emit * relative refs (`B2`), positional selectors emit absolute refs (`$B$2`), and a * `RANGE_REF` axis emits `$` exactly when it is `FIXED` (fill-pinned). The * computed value is identical either way; `$` only governs copy/fill inside Excel. */ export declare function serializeFormulaAstToExcel(ast: FormulaAstNode, context: FormulaExcelSerializeContext): FormulaExcelSerializeResult; /** * Maps an engine error code to the nearest Excel error sentinel. `#CYCLE!` has * no Excel equivalent (a circular reference is a reference problem → `#REF!`); * the generic `#ERROR!` maps to `#VALUE!`. */ export declare function mapFormulaErrorCodeToExcel(code: FormulaErrorCode): ExcelFormulaErrorCode;