# Defined names

Assign a name to a cell, range, or formula so it can be referenced by name from other formulas or charts instead of by address.

Two scopes are supported:

* **Workbook (global)** — visible from every worksheet.
* **Worksheet (local)** — visible only inside the worksheet whose name is passed as `$scopeSheet`.

## Function Prototype

```php
defineName(string $name, string $formula, ?string $scopeSheet = null): self
```

### **string $name**

> The name to define.

### **string $formula**

> Formula string. **Must start with `=`** and cell / range references must be absolute (use `$`).
>
> e.g. `=Sheet1!$A$1` or `=Sheet1!$B$2:$B$10`.

### **string $scopeSheet**

> Optional. When given, the name is local to that worksheet; otherwise the name is global.

## Example

```php
$config = [
    'path' => './tests'
];

$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('tutorial.xlsx', 'Sheet1');

$filePath = $fileObject->header(['name', 'amount'])
    ->data([
        ['viest', 1000],
        ['wjx',   2000],
    ])
    ->defineName('SalesTotal', '=Sheet1!$B$2')                   // global name
    ->defineName('LocalRange', '=Sheet1!$B$2:$B$3', 'Sheet1')    // local to Sheet1
    ->output();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xlswriter-docs.viest.me/english/defined-names.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
