export interface DefinedName { /** Identifier — `_xlnm.Print_Area` for built-ins, otherwise user-chosen. */ name: string; /** The formula expression the name points at. */ value: string; /** 0-based sheet index for sheet-scope names; undefined → workbook-scope. */ scope?: number; /** Hidden from the Name Manager when true. */ hidden?: boolean; /** Optional human-readable description. */ comment?: string; } export declare function makeDefinedName(opts: Partial & { name: string; value: string; }): DefinedName; import { type CellRangeBoundaries } from '../utils/coordinate'; import type { Worksheet } from '../worksheet/worksheet'; import type { Workbook } from './workbook'; /** * One parsed leg of a defined name's value. Defined-name values can be * comma-separated multi-range expressions (e.g. `_xlnm.Print_Titles` sets * `Sheet!$1:$1,Sheet!$A:$A`); this represents one such leg. */ export interface DefinedNameTarget { sheet: string; range: string; bounds: CellRangeBoundaries; } /** * Add a workbook-scope or sheet-scope defined name. If a defined name with the * same `name` (and `scope`) already exists, it's replaced — Excel allows one * workbook-scope and one per-sheet-scope name, but not two with the same scope. * Returns the resulting `DefinedName`. */ export declare const addDefinedName: (wb: Workbook, opts: Partial & { name: string; value: string; }) => DefinedName; /** * High-level: register a defined name pointing at a worksheet range. Combines * {@link getRangeAddress} (sheet-qualified, properly quoted) with {@link * addDefinedName}, so the caller doesn't have to assemble the formula string by * hand. * * Pass `opts.localToSheet: true` to scope the name to the worksheet (instead of * the workbook). Re-using the same `name` + scope replaces the previous entry * (Excel's per-scope-uniqueness rule). * * Throws when `localToSheet: true` is set but the worksheet isn't on * `wb.sheets` — that would be a stale Worksheet reference. */ export declare const addDefinedNameForRange: (wb: Workbook, name: string, ws: Worksheet, range: string, opts?: { localToSheet?: boolean; hidden?: boolean; comment?: string; }) => DefinedName; /** Look up a defined name by identifier and (optional) sheet scope. */ export declare const getDefinedName: (wb: Workbook, name: string, scope?: number) => DefinedName | undefined; /** * Resolve a defined name's `value` into one or more {@link DefinedNameTarget}s. * Comma-separated values (e.g. `_xlnm.Print_Titles` typically sets * `Sheet!$1:$1,Sheet!$A:$A`) yield one entry per leg; a plain `Sheet!A1:B5` * yields a single-element array. * * Returns `undefined` when the name doesn't exist; throws when the value can't * be parsed (e.g. a constant or a non-range formula — defined names are * sometimes used for things like `=42` or `=SUM(A:A)` which aren't ranges). */ export declare const getDefinedNameTarget: (wb: Workbook, name: string, scope?: number) => DefinedNameTarget[] | undefined; /** * Remove a defined name by identifier + scope. Returns true if any entry was * removed. */ export declare const removeDefinedName: (wb: Workbook, name: string, scope?: number) => boolean; /** * Read-only snapshot of every defined name. Pass `{ scope }` to narrow to * workbook-scope (`scope: undefined`) or one specific sheet (`scope: 0`) — omit * the option entirely to list all. */ export declare const listDefinedNames: (wb: Workbook, opts?: { scope?: number | "workbook" | "all"; }) => ReadonlyArray; /** * Bulk-remove every defined name matching `predicate`. Returns the count * removed. Mirrors {@link removeDataValidations} on worksheets. */ export declare const removeDefinedNames: (wb: Workbook, predicate: (d: DefinedName) => boolean) => number; /** * Rename a defined name, scoped or workbook-scope. Returns `true` when an entry * was renamed. Throws when `newName` is already taken with the same scope * (Excel forbids duplicates within a scope). */ export declare const renameDefinedName: (wb: Workbook, oldName: string, newName: string, scope?: number) => boolean; /** * Read-only snapshot of every `_xlnm.Print_Area` defined name. Each entry is * the raw DefinedName carrying `scope` (sheet index) and `value` (the * print-area expression like `'Sheet1'!$A$1:$D$10`). */ export declare const listPrintAreas: (wb: Workbook) => ReadonlyArray; /** * Read-only snapshot of every `_xlnm.Print_Titles` defined name. Each entry's * `value` is the title-row / title-col expression Excel re-uses on every * printed page. */ export declare const listPrintTitles: (wb: Workbook) => ReadonlyArray; /** * Define the print-area for a given sheet. Excel uses the built-in * `_xlnm.Print_Area` defined name with sheet scope. */ export declare const setPrintArea: (wb: Workbook, sheetIndex: number, ref: string) => DefinedName; /** * Define print-title rows / columns on a sheet. Excel uses the * `_xlnm.Print_Titles` defined name. Pass `rows` ("$1:$1") to repeat row 1 on * every printed page; `cols` ("$A:$A") to repeat column A. */ export declare const setPrintTitles: (wb: Workbook, sheetIndex: number, opts: { rows?: string; cols?: string; sheetName: string; }) => DefinedName;