/** * Workbook defined names (`CT_DefinedNames` / `CT_DefinedName`). * * Citations: * - ECMA-376-1 §18.2.5 `definedNames` / §18.2.6 `definedName` * - transitional sml.xsd `CT_DefinedNames` / `CT_DefinedName` / `CT_Workbook` sequence * - docs/specs/named-ranges.md; docs/ooxml-mapping/named-ranges.md * * Content text is opaque — never evaluated, never resolved as an external link. */ /** * Represents a named cell range or formula in a workbook, letting you refer * to it by name elsewhere in the document. */ export interface DefinedName { /** The name used in formulas — for example `'TaxRate'` or `'Sales'`. */ readonly name: string; /** * What the name refers to — for example `'Sheet1!$A$1:$A$10'` or `0.2`. * Stored as text and never evaluated by the library. */ readonly content: string; /** * The zero-based position of the sheet the name belongs to. `undefined` * when the name applies to the whole workbook. */ readonly sheetIndex?: number; /** * Whether the name is hidden from Excel's name manager. `undefined` means * not hidden. */ readonly hidden?: boolean; } /** * Represents the collection of defined names in a workbook, letting you add, * find, and remove named ranges and formulas. * * Key is `(name, sheetIndex | global)`. Same name may exist once globally and * once per local sheet index. {@link DefinedNames.add} is the sole public * add-or-replace write (API-RULES R1.5); `set` is `@private`. */ export interface DefinedNames { /** The number of defined names in the workbook. */ readonly count: number; /** * Get all defined names as a list, in the order they appear in the * workbook. * * @returns the current defined names. */ list(): ReadonlyArray; /** * Get a defined name by its name and optional scope. * * @param name - The name used in formulas, like `'TaxRate'`. * @param sheetIndex - The zero-based position of the sheet the name * belongs to; omit it (or pass `undefined`) to get the workbook-wide * entry. * @returns the matching defined name, or `undefined` when there is none. */ get(name: string, sheetIndex?: number): DefinedName | undefined; /** * Add a defined name, or update it when the same name already exists in * the same scope. A single leading `=` on `content` is stripped, so * `'=Sheet1!$A$1'` and `'Sheet1!$A$1'` are stored the same way. * * @param name - The name used in formulas, like `'TaxRate'`. * @param content - What the name refers to, like `'Sheet1!$A$1:$A$10'`. * @param sheetIndex - The zero-based position of the sheet the name belongs * to; omit / `undefined` for workbook-global. * @param hidden - When true, the name is hidden from Excel's name manager. * @returns an object describing the added or updated defined name. * @throws InvalidDefinedNameError when name or content is empty * @throws InvalidArgumentError when `sheetIndex` is out of sheet range */ add(name: string, content: string, sheetIndex?: number, hidden?: boolean): DefinedName; /** * Add or update a defined name without returning it. Prefer * {@link DefinedNames.add}, which returns the defined name. * * @param name - The name used in formulas, like `'TaxRate'`. * @param content - What the name refers to, like `'Sheet1!$A$1:$A$10'`. * @param sheetIndex - The zero-based position of the sheet the name belongs * to; omit / `undefined` for workbook-global. * @param hidden - When true, the name is hidden from Excel's name manager. * @throws InvalidDefinedNameError when name or content is empty * @throws InvalidArgumentError when `sheetIndex` is out of sheet range * * @private */ set(name: string, content: string, sheetIndex?: number, hidden?: boolean): void; /** * Remove a defined name. * * @param name - The name used in formulas, like `'TaxRate'`. * @param sheetIndex - The zero-based position of the sheet the name * belongs to; omit it (or pass `undefined`) for the workbook-wide * entry. * @returns `true` when a defined name was removed, `false` when none * matched. */ remove(name: string, sheetIndex?: number): boolean; /** Remove every defined name from the workbook. */ clear(): void; } /** * Internal record including preserve bag for unknown attributes. * @private */ export interface DefinedNameEntry { name: string; content: string; sheetIndex: number | undefined; hidden: boolean; /** Extra attributes excluding name / localSheetId (wire) / hidden (XML fragment, no leading space). */ extraAttrsXml: string; } /** * Host notifications for defined-name mutations and sheet-count checks. * @private */ export interface DefinedNamesHost { markDirty(): void; /** Current workbook sheet count (for sheetIndex validation). */ sheetCount(): number; } /** * Mutable defined-names store. * @private */ export declare class DefinedNamesImpl implements DefinedNames { private readonly entries; private host; constructor(initial?: ReadonlyArray); /** @private */ bindHost(host: DefinedNamesHost): void; readonly count: number; list(): ReadonlyArray; get(name: string, sheetIndex?: number): DefinedName | undefined; /** * Add or replace a defined name. * * Sole public defined-name write surface (API-RULES R1.5). * * Citations: ECMA-376-1 §18.2.5; docs/specs/defined-names.md; API-RULES R1.5. */ add(name: string, content: string, sheetIndex?: number, hidden?: boolean): DefinedName; /** * Internal void add-or-replace. Prefer {@link DefinedNames.add}. * * @private */ set(name: string, content: string, sheetIndex?: number, hidden?: boolean): void; remove(name: string, sheetIndex?: number): boolean; clear(): void; /** * Drop sheet-local names for `deletedIndex` and decrement higher ids. * Global name content is left unchanged (no formula rewrite). * @private */ onSheetRemoved(deletedIndex: number): void; /** * Remap sheet-local ids after a sheet reorder (`Array` move semantics). * @private */ onSheetMoved(fromIndex: number, toIndex: number): void; /** @private — snapshot for serialize */ toEntries(): ReadonlyArray; private findIndex; } /** * Parse a `definedNames` element string into entries. * @private */ export declare function parseDefinedNamesXml(definedNamesXml: string): DefinedNameEntry[]; /** * Serialize defined name entries to a `definedNames` element, or `undefined` when empty. * @private */ export declare function serializeDefinedNamesXml(entries: ReadonlyArray): string | undefined; /** * XSD relative rank for workbook children (lower = earlier). * `sheets` = 50; `definedNames` = 80. * @private */ export declare function workbookChildOrderRank(localName: string): number;