HotXLS Docs

TXLSXDefinedName / TXLSXDefinedNames classes

Workbook-level named ranges (also called defined names). Each entry maps a name (e.g. SalesData) to a formula that typically refers to a cell range. Names can be workbook-scoped (visible from any worksheet) or sheet-scoped (visible only on a single worksheet). The collection lives on TXLSXWorkbook.DefinedNames. Declared in lxHandleX.

TXLSXDefinedName declaration

type
  TXLSXDefinedName = class
    constructor Create(const AName, AFormula: WideString; ASheetIndex: Integer = -1);
    property Name: WideString;
    property Formula: WideString;
    property SheetIndex: Integer;
    property Hidden: Boolean;
    property Comment: WideString;
  end;
      

TXLSXDefinedName members

Name The defined-name identifier (must follow Excel's naming rules: starts with letter or underscore, no spaces).
Formula The expression the name refers to, usually a range reference such as 'Sheet1!$A$1:$B$10'.
SheetIndex 0-based sheet index for sheet-scoped names; use -1 for workbook-scoped names (the default). When set, SaveAs emits the localSheetId attribute.
Hidden When True, the name is hidden from the Excel Name Manager UI and formula-bar drop-down. Emits hidden="1" on the <definedName> element.
Comment Optional description for the defined name, visible in the Excel Name Manager dialog. Emits a comment="..." attribute on the <definedName> element when non-empty.

TXLSXDefinedNames declaration

type
  TXLSXDefinedNames = class
    function Add(const AName, AFormula: WideString): Integer; overload;
    function Add(const AName, AFormula: WideString; ASheetIndex: Integer): Integer; overload;
    function IndexOfName(const AName: WideString): Integer;
    procedure Clear;
    property Count: Integer;
    property Items[Index: Integer]: TXLSXDefinedName; default;
  end;
      

TXLSXDefinedNames members

Add(Name, Formula) Workbook-scoped shortcut. Returns the new index.
Add(Name, Formula, SheetIndex) Sheet-scoped overload. Pass the 0-based worksheet index. Returns the new index.
IndexOfName(Name) Case-insensitive name lookup. Returns -1 if no defined name matches.

Example

begin
  Workbook.DefinedNames.Add('SalesData', 'Sheet1!$A$1:$B$10');
  Workbook.DefinedNames.Add('TaxRate', 'Sheet1!$C$1', 0); // sheet-scoped
end;
    

See also