SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface INamedCollection

    A collection of INamed items — defined names AND tables.

    Which items it holds is decided by where you got it from, not by an option. There is no scope argument anywhere on this interface:

    Reached through Holds
    IWorkbook.getNames EVERY named item in the workbook, whatever its scope
    ISheet.getNames only what is visible FROM that sheet — the global items (tables included) plus that sheet's own, shadowing resolved

    The two exist because the two consumers genuinely differ: a name manager lists everything that exists, while a formula editor may only offer what a formula written here can actually refer to. Both get it from getItems() with no arguments, which is the point — the scope question is answered by the call you make, so it cannot be got wrong by omitting an option.

    Scope is visibility, never location. A defined name lives on no sheet and may be visible everywhere or on exactly one sheet. A table lives ON a sheet but its name is always visible everywhere and workbook-unique — so getScope() is null for every table, and tables appear in BOTH collections. That is not a special case: they are globally visible, so they turn up wherever globally visible items do. For the tables anchored to one sheet, ask ISheet.getTables() — that is the location question, and it has its own call.

    Porting from Excel's Office Scripts. Deliberately close but not identical. There, Workbook.getNames() is global-scoped names ONLY and Worksheet.getNames() is that sheet's own ONLY, with tables kept out of names entirely. Both of ours are supersets of their counterpart, so a direct port is over-inclusive rather than wrong — it will never see another sheet's private names. Filter on INamed.getScope (null = global) for exact parity.

    interface INamedCollection {
        isICollection: true;
        isINamedCollection: true;
        "[iterator]"(): IterableIterator<INamed<any>>;
        addFormula(
            name: string,
            expression: string,
            replaceExisting?: boolean,
        ): INamed;
        addListeners(
            listeners: INamedCollection.IListeners,
            options?: IListener.Options,
        ): Remove;
        at(index: number): INamed<any> | undefined;
        close(): void;
        every(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => boolean,
        ): boolean;
        filter<S extends INamed<any>>(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => value is S,
        ): S[];
        filter(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => boolean,
        ): INamed<any>[];
        find<S extends INamed<any>>(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => value is S,
        ): S | undefined;
        find(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => boolean,
        ): INamed<any> | undefined;
        findIndex(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => boolean,
        ): number;
        findValidName(
            template: string,
            scope?: string,
            ignoreExisting?: boolean,
        ): string;
        forEach(
            fn: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => void,
        ): void;
        getById(id: string): INamed<any> | null;
        getByName(name: string, global?: boolean): INamed<any> | null;
        getByRanges(
            ranges: ICellRanges.Address,
            options?: GetByRangesOptions,
        ): string[];
        getCount(): number;
        getItems(options?: INamedCollection.GetItemsOptions): INamed<any>[];
        indexOf(item: INamed): number;
        isClosed(): boolean;
        map<U>(
            fn: (value: INamed, index: number, items: readonly INamed<any>[]) => U,
        ): U[];
        some(
            predicate: (
                value: INamed,
                index: number,
                items: readonly INamed<any>[],
            ) => boolean,
        ): boolean;
        toArray(): INamed<any>[];
        validateName(name: string, scope?: string, ignoreExisting?: boolean): void;
    }

    Hierarchy (View Summary)

    Index
    isICollection: true

    For runtime type checking.

    isINamedCollection: true

    For runtime type checking.

    • Iterates the collection's items.

      Returns IterableIterator<INamed<any>>

      The unfiltered walk — for (const sheet of wb.getSheets()). Every other iterable surface in the SDK (ICellRange, ICellRegions, ICellRanges) reads this way, so a collection that did not was a trap: for…of over one is the obvious line to write and it threw at runtime with nothing in the types to warn first.

      getItems remains the call that takes options — filtering, ordering, anything parameterized. This is sugar over the unfiltered case, not a replacement for it.

    • Define a name.

      Parameters

      • name: string

        The name. Case insensitive, must be unique, and must not contain spaces.

      • expression: string

        The expression to bind it to, with or without a leading =. A plain range address (Sheet1!$A$1:$B$2) is simply a reference expression.

      • OptionalreplaceExisting: boolean

        If true, redefine an existing name instead of throwing. default false.

      Returns INamed

      Error if the name is invalid, or already exists and replaceExisting is not set.

      Created in the registry that owns defined names — the calculation engine — so it is the same kind of item as one loaded from a file, and getType() is 'formula'. Use ICalculation.INamedFormula.setExpression to redefine it afterwards.

    • Returns the item at the given index, or undefined if there is none.

      Parameters

      • index: number

        The position in iteration order. A negative index counts back from the end, as Array.prototype.at does.

      Returns INamed<any> | undefined

    • Close the record and cleans resources. Can't be undone.

      Returns void

    • Returns true if the predicate accepts every item, including when there are none.

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => boolean

        Called once per item in iteration order until it returns false.

      Returns boolean

    • Returns the items the predicate accepts, in iteration order.

      Type Parameters

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => value is S

        Called once per item.

      Returns S[]

    • Returns the items the predicate accepts, in iteration order.

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => boolean

        Called once per item.

      Returns INamed<any>[]

    • Returns the first item the predicate accepts, or undefined if it accepts none.

      Type Parameters

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => value is S

        Called once per item in iteration order until it returns true.

      Returns S | undefined

    • Returns the first item the predicate accepts, or undefined if it accepts none.

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => boolean

        Called once per item in iteration order until it returns true.

      Returns INamed<any> | undefined

    • Returns the index of the first item the predicate accepts, or -1 if it accepts none.

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => boolean

        Called once per item in iteration order until it returns true.

      Returns number

    • Returns a new valid name given the name return a valid name that closely matches. This function works by incrementing either the last number or append a number.

      Parameters

      • template: string

        The range to used as a template.

      • Optionalscope: string

        The scope of the range. If null then this will look for a globally scoped. default null.

      • OptionalignoreExisting: boolean

        If true then won't check to see if the name is already used. default false.

      Returns string

      A valid name. If the name used is valid then will return the same name.

      Error If the template name is invalid.

    • Calls the function once per item, in iteration order.

      Parameters

      • fn: (value: INamed, index: number, items: readonly INamed<any>[]) => void

        Called once per item.

      Returns void

    • Lookup a named item by its unique stable id.

      Parameters

      Returns INamed<any> | null

    • Lookup a named range with a given name.

      Parameters

      • name: string

        Case insensitive name to lookup.

      • Optionalglobal: boolean

        If true then will search all scopes. default false.

      Returns INamed<any> | null

    • The reference text for every name that designates exactly the given ranges.

      Parameters

      Returns string[]

      The names, whole-item matches first, then part references. Empty when nothing matches.

      The inverse of resolving a name: given a region, what is it called? This is what lets a name box show Sales in place of $B$2:$C$3, and what lets a formula editor substitute the name for an address the user picked by dragging.

      Exact, not containing. A selection inside Sales is not Sales — the ranges must coincide. Multi-range names match irrespective of the order the ranges are given in.

      Text, not items. A part has no INamed to return (Sales[Amount] is a structured reference, not an entry in this collection), so every match comes back as the text a formula would use. Several names may share one region, hence an array; callers wanting a single answer take the first.

    • Returns the total items available.

      Returns number

      returns the total number of items available.

    • Returns the index of the item in iteration order, or -1 if it is not in the collection.

      Parameters

      • item: INamed

        The item to find.

      Returns number

    • Returns true if no more operations are allowed.

      Returns boolean

    • Returns the result of calling the function on every item, in iteration order.

      Type Parameters

      • U

      Parameters

      • fn: (value: INamed, index: number, items: readonly INamed<any>[]) => U

        Called once per item.

      Returns U[]

    • Returns true if the predicate accepts at least one item.

      Parameters

      • predicate: (value: INamed, index: number, items: readonly INamed<any>[]) => boolean

        Called once per item in iteration order until it returns true.

      Returns boolean

    • Returns the items as a fresh array, in iteration order.

      Returns INamed<any>[]

      The call to make when an array is really wanted. The array is the caller's: changing it does not change the collection, and it does not follow later changes to the collection.

    • Validates a name is valid. This is a convenience method That calls findValidName and throws an error if the name returned is not the same.

      Parameters

      • name: string
      • Optionalscope: string
      • OptionalignoreExisting: boolean

      Returns void

      Error If findValidName does not return the same value as the name checking.