# Data tools

> Data validation with dropdown lists, autofilter, sort, find and replace, the fill handle, clipboard, undo and redo, and the full keyboard shortcut list.

The spreadsheet includes the data tools people expect from Excel. Each one is available to users through the keyboard and the cell menu, and to you through the API.

## Data validation

Validation rules restrict what users can type into cells: a value from a list, a number in a range, a date in a window, text of a certain length, or anything a formula accepts.

**`DataValidation`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface DataValidation
```

| Property | Type | Description |
| --- | --- | --- |
| `range` | `string` |  |
| `type` | `ValidationType` |  |
| `operator?` | `ComparisonOperator` |  |
| `values?` | `(number \| string)[]` |  |
| `source?` | `string` |  |
| `formula?` | `string` |  |
| `allowBlank?` | `boolean` |  |
| `showDropdown?` | `boolean` |  |
| `errorStyle?` | `'stop' \| 'warning' \| 'information'` |  |
| `errorTitle?` | `string` |  |
| `errorMessage?` | `string` |  |
| `prompt?` | `string` |  |
| `promptTitle?` | `string` |  |

### Dropdown lists

```ts
sheet.addValidation({
  range: 'C2:C200',
  type: 'list',
  values: ['Open', 'Approved', 'Rejected', 'Paid'],
  prompt: 'Choose the invoice status.',
});

sheet.addValidation({ range: 'D2:D200', type: 'list', source: '=Lists!$A$2:$A$40' });
sheet.addValidation({ range: 'E2:E200', type: 'list', source: 'EUR, GBP, USD' });
```

A list comes from `values`, from a comma-separated `source`, or from a `source` formula such as a range on a lookup sheet, which keeps the dropdown in sync with the data. Cells with a list show a dropdown button while they are the active cell, unless `showDropdown` is `false`, and `Alt` + `Arrow Down` opens it from the keyboard. The button is drawn just outside the right border of the cell, where Excel draws it, when the next cell is empty. When the next cell has content the button is drawn inside the active cell at its right edge and the cell text makes room for it, so the button never covers a value. To show the arrow all the time, use the [`dropdown` cell control](https://docs.birchui.com/spreadsheet/formatting.md#cell-controls). Matching ignores case.

### Numbers, dates and text length

```ts
sheet.addValidation({
  range: 'B2:B200',
  type: 'decimal',
  operator: 'between',
  values: [0, 50000],
  errorTitle: 'Invoice amount',
  errorMessage: 'Enter an amount between 0 and 50,000.',
});

sheet.addValidation({ range: 'F2:F200', type: 'date', operator: 'greaterThanOrEqual', values: ['=TODAY()'] });
sheet.addValidation({ range: 'G2:G200', type: 'textLength', operator: 'lessThanOrEqual', values: [140] });
sheet.addValidation({ range: 'H2:H200', type: 'whole', operator: 'greaterThan', values: [0] });
```

`whole` accepts whole numbers only, `decimal` any number, `date` date serials, and `textLength` checks the number of characters. The `operator` defaults to `between`, and `values` can be numbers or formulas starting with `=`.

### Custom formulas

A `custom` rule accepts a value when its formula is true. Write it for the top-left cell of the range; relative references shift for the other cells. This allows each invoice number only once:

```ts
sheet.addValidation({
  range: 'A2:A200',
  type: 'custom',
  formula: '=COUNTIF($A$2:$A$200, A2) = 1',
  errorMessage: 'This invoice number is already in the list.',
});
```

### What happens on invalid input

| `errorStyle` | Behaviour |
| --- | --- |
| `'stop'` (default) | The input is rejected and the cell keeps its previous value. |
| `'warning'`, `'information'` | The input is accepted and the user is told it does not match. |

In each case the spreadsheet emits an `error` event with the code `validation`, the message and the cell address, and announces the message to screen readers. Without an `errorMessage`, a message is built from the rule, such as "Enter a number between 0 and 50000." `prompt` shows a hint when the cell is selected. Empty input is allowed unless `allowBlank` is `false`.

By default validation applies to what users type. Values set with the API, pasted or filled are not checked against the rules; the next section changes that. `clearValidations(sheet?)` removes all rules from a sheet. Rules are saved in the workbook JSON and in [xlsx files](https://docs.birchui.com/spreadsheet/xlsx.md#what-round-trips).

### Validation beyond typed input

Set `validation: 'always'` to apply the rules to every way a value can reach a cell:

```ts
const sheet = createSpreadsheet(container, { data: workbook, validation: 'always' });
```

| `validation` | Typed input | Paste, fill, flash fill, replace | `setValue`, `setFormula`, `setRange` |
| --- | --- | --- | --- |
| `'ui'` (default) | Checked | Not checked | Not checked |
| `'always'` | Checked | Checked: invalid cells are skipped | Checked: the call throws |

Only rules with the error style `'stop'` (the default) reject a value. `'warning'` and `'information'` rules never block these paths and report nothing for them.

**Paste, fill, flash fill and replace** write the cells that pass and leave the others as they were. One `error` event with the code `validation` reports how many cells were skipped and carries the sheet and address of the first one; the same message is announced to screen readers. This covers `Ctrl+V`, paste special, dragging cells with `Ctrl` held, the fill handle, `Ctrl+D` and `Ctrl+R`, `Ctrl+Enter` in the editor, flash fill, and Replace all. Moving cells, by cut and paste or by dragging, is all or nothing: if a moved value would break a rule at its destination, nothing moves.

**API writes** (`setValue`, `setFormula`, `setRange`, and the formula `autoSum` writes) throw a `ValidationError` and change nothing. `setRange` is all or nothing as well: one invalid cell rejects the whole block.

```ts
import { ValidationError } from '@birchui/spreadsheet';

try {
  sheet.setRange('B2', importedRows);
} catch (error) {
  if (!(error instanceof ValidationError)) throw error;
  console.warn(`${error.sheet}!${error.address} and ${error.rejected - 1} more cells were rejected`);
}

sheet.setValue('B4', 99999, { force: true });
```

The `error` event fires for a rejected API write too. `{ force: true }` as the last argument writes without checking; it works on `setValue`, `setFormula`, `setRange`, `pasteSpecial`, `flashFill` and `replaceAll`. See [Write options](https://docs.birchui.com/spreadsheet/api.md#write-options).

Details:

- A formula is judged by the value it would have at the moment it is written, both through the API and when typed. A formula whose result is an error, including `#BUSY!` from an async function, is accepted, and the result is not checked again when it changes later.
- Clearing is never rejected in these paths, even where a rule has `allowBlank: false`. `clearRange()` and an empty pasted cell always go through.
- Undo and redo restore earlier values without checking them.
- Text to columns, sorting, remove duplicates, `setHyperlink()`, pivot table output and loading a workbook are not checked.
- `update({ validation })` switches the mode at runtime. Values that are already in the sheet are not re-checked.
- The headless [formula engine](https://docs.birchui.com/spreadsheet/headless-engine.md) stores validation rules but does not apply them; this option belongs to the component.

## Autofilter

```ts
sheet.setAutoFilter('A1:F200');
sheet.setAutoFilter(null);
```

An autofilter adds a dropdown to each header cell of the range, with **Sort A to Z**, **Sort Z to A**, a search box and a checklist of the values in that column. Unticking values hides the rows that contain them. Typing in the search box narrows the list, and **OK** then keeps only the matches. Users toggle the filter with `Ctrl` + `Shift` + `L`. The state is saved in the sheet's `autoFilter` as the range and, per column, the values that are shown.

### Filter by condition, rank, colour or date

The dropdown's **Filter by condition, colour or rank** section, and `setColumnFilter(column, condition)` in code, filter by more than a list of values:

**`FilterCondition`** (type from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
type FilterCondition =
  | {
      kind: 'condition';
      operator:
        | 'equals'
        | 'notEquals'
        | 'greaterThan'
        | 'greaterThanOrEqual'
        | 'lessThan'
        | 'lessThanOrEqual'
        | 'between'
        | 'contains'
        | 'notContains'
        | 'beginsWith'
        | 'endsWith';
      value: string | number;
      value2?: string | number;
    }
  | { kind: 'top'; direction: 'top' | 'bottom'; count: number; percent?: boolean }
  | { kind: 'color'; target: 'fill' | 'font'; color: string | null }
  | { kind: 'dateGroup'; year: number; month?: number; day?: number }
  | { kind: 'values'; values: string[] };
```

```ts
sheet.setAutoFilter('A1:F200');
sheet.setColumnFilter('E', { kind: 'condition', operator: 'between', value: 500, value2: 2000 });
sheet.setColumnFilter('B', { kind: 'condition', operator: 'contains', value: 'gmbh' });
sheet.setColumnFilter('E', { kind: 'top', direction: 'top', count: 10 });
sheet.setColumnFilter('E', { kind: 'top', direction: 'bottom', count: 5, percent: true });
sheet.setColumnFilter('C', { kind: 'color', target: 'fill', color: '#FFEB9C' });
sheet.setColumnFilter('D', { kind: 'dateGroup', year: 2026, month: 3 });
sheet.setColumnFilter('C', { kind: 'values', values: ['Open', 'Approved'] });
sheet.setColumnFilter('E', null);
```

- **Conditions** compare numbers numerically and text without regard to case. `equals` and `notEquals` accept the `*` and `?` wildcards.
- **Top and bottom** keep the N largest or smallest numbers, or N percent of them, including ties.
- **Colour** matches the cell's own fill or text colour; `color: null` keeps cells without one. It is evaluated row by row, so two cells with the same value and different colours are told apart.
- **Dates**: a column of dates shows a year and month tree instead of a flat list.

Filters on several columns combine. Inside a [table](https://docs.birchui.com/spreadsheet/tables.md) the same call filters the table.

### Saved filter state

The filter state lives in the workbook JSON, so it survives `toJSON()` and `fromJSON()` and shows on the filter buttons after loading:

- `autoFilter.columns` holds, per column index, the display values that are shown.
- `autoFilter.criteria` holds conditions and top/bottom rules as [`FilterCriteria`](https://docs.birchui.com/spreadsheet/api.md), the form Excel files use: `{ type: 'custom', conditions, matchAll? }` or `{ type: 'top', value, bottom?, percent? }`. `contains`, `beginsWith` and `endsWith` are stored as `equal` with wildcards.
- A table keeps the same two maps in its `filter` property.

Column keys are zero-based sheet column indexes. Colour and date-group filters have no criteria form; they are saved as the list of values they let through.

### Filters and sort order from Excel files

A file can carry filters that are not value lists: by cell or font colour, by conditional-format icon, or by date group (a whole year or month). They arrive in `autoFilter.special`, or in `filter.special` of a table, and are applied on load: the other rows are hidden, the filter button shows as active, and the dropdown shows the filter, with the colour selected, the months ticked, or **Cell icon** chosen. Filters on other columns combine with it. Applying or clearing a filter on that column from the dropdown replaces it with an ordinary filter.

The sort of a filtered range is kept in `sortState` on the sheet, and on the table for tables. The sorted column shows an arrow on its filter button and the matching sort button in the dropdown is marked. Sorting from the dropdown, the Sort dialog, `sortRange()` or `sortRangeBy()` inside a filtered range or a table writes `sortState`.

The sort buttons in the dropdown are named after the data in the column: **Sort A to Z** and **Sort Z to A** for text, **Sort Smallest to Largest** and **Sort Largest to Smallest** for numbers, **Sort Oldest to Newest** and **Sort Newest to Oldest** for dates.

## Sort

```ts
sheet.sortRange('A2:F200', 'D', true);
sheet.sortRange('A2:F200', 1);
```

`sortRange(range, column, descending?)` sorts the rows of a range by one column, given by letter or 1-based number. Leave the header row out of the range. Formulas move with their rows. From the toolbar or the cell menu, **Sort A to Z** and **Sort Z to A** sort the selection, or the block of data around the active cell, by the active cell's column, keeping an autofilter's header in place.

### Multi-level sort

```ts
sheet.sortRangeBy(
  'A1:F200',
  [
    { column: 'C', customList: ['High', 'Medium', 'Low'] },
    { column: 'B' },
    { column: 'F', descending: true },
  ],
  { hasHeaders: true },
);
```

`sortRangeBy(range, levels, options?)` sorts by several columns in order. A level may name a `customList`: values in the list sort in list order, ahead of values that are not in it. `hasHeaders` keeps the first row in place and `matchCase` makes text comparison case-sensitive. Blank cells always sort last.

**Data › Sort** opens the same thing as a dialog: add, remove and reorder levels, pick a column by its header, and choose ascending, descending or one of your [`customLists`](#autofill-series-and-custom-lists) as the order.

## Remove duplicates

```ts
const removed = sheet.removeDuplicates('A1:E500', { hasHeaders: true, columns: ['A', 'C'] });
```

Rows that repeat an earlier row are removed and the rows below move up. Without `columns` every column of the range is compared. Text compares without regard to case, and the first occurrence is kept. The dialog, **Data › Remove duplicates**, lists the columns by header.

## Text to columns

```ts
sheet.textToColumns('A2:A500', { delimiters: [','], destination: 'B2' });
sheet.textToColumns('A2:A500', { delimiters: [' ', ';'], treatConsecutiveAsOne: true });
sheet.textToColumns('A2:A500', { fixedWidths: [3, 9] });
```

**`TextToColumnsOptions`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface TextToColumnsOptions
```

| Property | Type | Description |
| --- | --- | --- |
| `delimiters?` | `string[]` |  |
| `fixedWidths?` | `number[]` |  |
| `treatConsecutiveAsOne?` | `boolean` |  |
| `textQualifier?` | `string` |  |
| `destination?` | `string` |  |

Each cell of a one-column range is split into pieces that are written to the right, starting at `destination` or in place. Pieces are read like typed input, so `18.5` becomes a number and `2026-03-01` a date. A `textQualifier` (`"` by default) keeps delimiters inside quotes together. The dialog previews the first row.

## Flash fill

Type what you want in the first one or two cells of an empty column next to your data, then choose **Data › Flash fill** or call `flashFill()`:

```ts
sheet.setValue('B2', 'Maria');
sheet.select('B3');
sheet.flashFill();
```

The spreadsheet looks for one rule that turns the neighbouring columns into your examples and applies it to the empty cells below: a word or part of a value, several pieces joined with text between them, initials, the part before or after a character such as `@`, and upper, lower or proper case. If no rule fits it says so and changes nothing. `flashFill(range)` targets a specific column and returns the number of cells it filled.

## Subtotals

```ts
sheet.subtotal('A1:D200', { groupBy: 'A', function: 'sum', columns: ['D'] });
sheet.removeSubtotals('A1:D260');
```

**`SubtotalOptions`** (interface from `@birchui/spreadsheet`, full reference: https://docs.birchui.com/api/spreadsheet.md)

```ts
interface SubtotalOptions
```

| Property | Type | Description |
| --- | --- | --- |
| `groupBy` | `number \| string` |  |
| `function?` | `SubtotalFunction` |  |
| `columns` | `(number \| string)[]` |  |
| `hasHeaders?` | `boolean` |  |
| `replace?` | `boolean` |  |

Sort by the grouping column first. At each change in that column a row such as **Lisbon Total** is inserted with `SUBTOTAL` formulas for the chosen columns, a **Grand Total** row closes the range, and the detail rows are [grouped](https://docs.birchui.com/spreadsheet/outline.md) so the outline buttons collapse them. Rows below the range move down. `function` is `sum`, `count`, `average`, `max` or `min`. Running it again replaces the existing subtotals unless `replace` is `false`.

## Goal seek

```ts
sheet.setFormula('B4', '=-PMT(B2/12, B3*12, B1)');
const result = sheet.goalSeek({ setCell: 'B4', toValue: 1500, changingCell: 'B1' });
// { found: true, value: 269865.48, result: 1500, iterations: 6 }
```

Goal seek changes one input cell until a formula returns the value you ask for. `setCell` must contain a formula and `changingCell` a plain value. When a solution is found the input is updated as one undo step; otherwise the sheet is left as it was and `found` is `false`. **Data › Goal seek** opens it as a dialog.

## Data tables

A data table shows what a formula returns for a list of input values, without changing the model. It is Excel's **What-If Analysis › Data Table**.

```ts
sheet.setRange('A1', [
  ['Principal', 250000],
  ['Annual rate', 0.06],
  ['Years', 30],
  ['Payment', '=-PMT(B2/12, B3*12, B1)'],
]);
sheet.setRange('D1', [
  ['=B4', 15, 20, 30],
  [0.04],
  [0.05],
  [0.07],
]);
sheet.addDataTable({ range: 'D1:G4', rowInputCell: 'B3', columnInputCell: 'B2' });
sheet.getValue('E2'); // the payment at 4% over 15 years
```

`range` is the whole table: the formula, the input values and the cells for the results. The three layouts are Excel's:

| Layout | Input cells | Formulas | Input values |
| --- | --- | --- | --- |
| Two variables | `rowInputCell` and `columnInputCell` | One, in the top-left cell | Along the top row for the row input cell, down the left column for the column input cell |
| One variable by column | `columnInputCell` | One or more, in the top row from the second column on | Down the left column |
| One variable by row | `rowInputCell` | One or more, in the left column from the second row on | Along the top row |

Each result cell holds the value its formula returns when the input cells are replaced by the values from the table's edges. The input cells themselves keep their content, and no `cellChange` event or collaboration operation is produced for the replacement. An input cell must be a single cell on the same sheet, outside the table. It usually holds a plain value; a formula there is put back unchanged.

The results are recalculated at the end of a recalculation whenever an input value in the table, one of its formulas or any cell those formulas depend on has changed. A formula that returns an error shows that error in its result cell and leaves the others alone. A table whose formula reads the table's own results is calculated at most four times per recalculation.

Result cells are values, not formulas. In the component they are read-only: typing into one is refused, a paste, fill, replace, `setValue()` or `setRange()` that covers result cells leaves those cells out, and sorting, moving, removing duplicates from, splitting or subtotalling a range that touches them is refused. Each of these emits the `error` event with the code `dataTable` and the message "That cell is part of a data table…". Formatting result cells is allowed. Selecting every result cell and pressing `Delete` removes the table. In code:

| Method | Purpose |
| --- | --- |
| `addDataTable({ range, rowInputCell?, columnInputCell? })` | Adds a table and fills its results, as one undo step. Throws a `DataTableError` for a range with fewer than two rows or columns, a missing or invalid input cell, an input cell inside the range, a range that overlaps another data table, or more than 20,000 result cells. |
| `removeDataTable(range, options?)` | Removes every data table that touches `range` and clears its results; `{ keepValues: true }` leaves the last results as plain values. Returns `false` when there is none. |
| `getDataTables(sheet?)` | The definitions, each with its `sheet`. |

The definitions are saved in the workbook JSON as `dataTables` on the sheet, next to the result values. Inserting or deleting rows and columns moves the range and the input cells; deleting an input cell, or all but one row or column of the table, removes the definition and leaves the values. Data tables are written to and read from [xlsx](https://docs.birchui.com/spreadsheet/xlsx.md#data-tables-in-files) and [ods](https://docs.birchui.com/spreadsheet/file-formats.md#what-an-ods-file-carries) files.

**Data › Data table** opens a dialog with the table range (the selection), the row input cell and the column input cell. `openDialog('dataTable')` opens it from code.

Things to know:

- Every result cell costs one recalculation of the cells that depend on the input cells, so a table of 50 by 50 results recalculates that part of the model 2,500 times whenever it is refreshed. There is no "automatic except data tables" mode.
- Volatile functions such as `RAND()` in the formula make the table refresh on every recalculation.
- With [worker calculation](https://docs.birchui.com/spreadsheet/worker-calculation.md) the tables are calculated in the worker with everything else, and the result cells keep their previous values until the worker answers.
- A formula that reaches the input cell through an [async custom function](https://docs.birchui.com/spreadsheet/formulas.md#async-functions) shows `#BUSY!` in the results until the call for each input value has resolved; the table then refreshes by itself.
- The headless engine does not reject a write into a result cell; the table puts its result back at the end of that recalculation.

## Find and replace

`Ctrl` + `F` opens find, and `Ctrl` + `H` find and replace. In code:

```ts
const matches = sheet.find('Northwind', { matchCase: false, allSheets: true });
const replaced = sheet.replaceAll('Northwind Ltd', 'Northwind Traders', { wholeCell: true });
```

| Option | Effect |
| --- | --- |
| `matchCase` | Distinguish upper and lower case. |
| `wholeCell` | Match the entire cell content only. |
| `inFormulas` | Search formula text instead of displayed values. |
| `allSheets` | Search every sheet; addresses are then returned as `Sheet!A1`. |

`find()` returns the addresses of matching cells; `replaceAll()` returns how many cells changed. Replacements are one undoable step and emit `cellChange` with the source `replace`.

## Spelling

The spreadsheet ships no dictionary. Pass a function as `spellcheck` and **Review > Spelling** (`F7`) walks the cells it reports. The function has the same contract as the one the Document Editor takes: it receives one text and a language tag and returns the ranges that are wrong, at once or as a promise.

```ts
const sheet = createSpreadsheet(host, {
  locale: 'en-GB',
  spellcheck: async (text, language) => {
    const response = await fetch('/api/spell', { method: 'POST', body: JSON.stringify({ text, language }) });
    return response.json(); // [{ from: 3, to: 10, suggestions: ['receive'], message: 'Spelling' }]
  },
});
```

The request in this example is made by your code; the component itself never contacts a server. The language is the `locale` option when it is a tag, else the `lang` of the page, else `en`.

The dialog starts at the active cell, goes across each row and down, wraps to the top, and stops after one pass. With more than one cell selected it checks the selection only. It checks cells that hold typed text: numbers, formulas, hidden rows and hidden columns are skipped. For each word it selects the cell, shows the word in its sentence and offers:

| Button | Effect |
| --- | --- |
| Change | Replaces this occurrence with the text in **Change to**, which starts as the first suggestion. `Enter` does the same. |
| Change all | Replaces the word in every cell of the pass. |
| Ignore once | Leaves this occurrence. |
| Ignore all | Leaves the word everywhere until the spreadsheet is destroyed. Case is not compared. |

Every replaced cell is one undo step, and text formatted in parts keeps the formatting of the run the word was in. The same steps are available in code:

```ts
const issues = await sheet.checkSpelling(); // the active sheet, or checkSpelling('A2:D40')
// [{ sheet: 'Notes', address: 'A1', from: 3, to: 10, text: 'recieve', suggestions: ['receive'] }]
sheet.replaceSpelling(issues[0], 'receive');
sheet.ignoreSpelling('Northwind');
sheet.getSpellingIssues(); // what the last check found, minus what was replaced or ignored
```

A function that throws is reported with `console.error` and its text is treated as correct. Ranges outside the text are dropped. Words are not underlined in the grid, the ignore list is not saved with the workbook, and notes, comments, chart titles and shapes are not checked.

## Date picker

A double click, or `Alt` + `Down`, on a cell opens a calendar when the cell has a date number format (and is empty or holds a number) or a data validation rule of type `date`. Cells with a formula, text cells and read-only workbooks are left alone, and a double click there starts editing as before. Typing and `F2` still edit a date cell directly.

| Key | Moves |
| --- | --- |
| Arrow keys | One day, or one week up and down |
| `Home`, `End` | To the first or last day of the week |
| `Page Up`, `Page Down` | One month; with `Shift`, one year. A day that the month does not have becomes its last day. |
| `Enter`, `Space` | Writes the focused date and closes |
| `Tab` | Between the day grid, **Today** and the month buttons |
| `Escape` | Closes without a change |

The chosen date goes through the same path as typed input, so validation, protection and undo apply. The calendar opens on the cell's date, or on today, starts the week on the first weekday of the `locale`, and names months and days in that language. Set `datePicker: false` to switch it off. It picks dates only: a time part in the cell is replaced by midnight, and there is no range or time picker.

## Autocomplete and the pick list

While you type text in a cell, the spreadsheet looks at the entries directly above and below in the same column. As soon as exactly one of them starts with what you typed, the rest of that entry is proposed and selected in the editor: `Enter` or `Tab` accepts it (with the capitalisation of the existing entry), typing on replaces it, `Delete` or `Backspace` removes it. Nothing is proposed for numbers, dates, formulas, or while several entries still match. Set `autoComplete: false` to turn it off.

`Alt` + `↓` on any cell, or **Pick from list…** in the cell menu, opens the same entries as a sorted list; arrow keys and `Enter` write one into the cell. On a cell with a list validation the shortcut opens the validation's choices instead.

## Go To and Go To Special

`Ctrl` + `G` or `F5` opens **Go to**. Type a cell, a range such as `B2:D9`, several ranges separated by commas, a reference on another sheet (`Rates!A1`) or a defined name, or pick an entry from the list: the last places you came from, the defined names and the tables. `Enter` goes there. **Home › Go to** opens the same dialog.

**Special…** in that dialog, or **Home › Go to › Go to special…**, selects cells by what they hold:

| Choice | Selects |
| --- | --- |
| Blanks | Empty cells inside the used range |
| Constants | Cells with a typed value |
| Formulas | Cells with a formula |
| Errors | Cells that show an error value |
| Visible cells only | The selection without hidden or filtered-out rows and columns |
| Current region | The block of filled cells around the active cell |
| Conditional formats | Cells that a conditional formatting rule applies to |
| Data validation | Cells with a validation rule |
| Notes and comments | Cells with a note or a comment thread |
| Last cell | The last used cell of the sheet |

With one cell selected the whole sheet is searched; with a range selected, only that range. If nothing matches, the dialog stays open and says so. The most used choices are also direct entries of the **Go to** menu.

After **Visible cells only**, `Ctrl` + `C` copies just those cells: hidden rows are left out and the copy pastes as one block. The same works for any multiple selection whose ranges share their columns or their rows.

```ts
sheet.goTo('Leads');                       // true when the reference exists
sheet.selectSpecial('blanks', 'B2:F40');   // ['C7', 'E12:E14']
sheet.selectSpecial('visibleCells');
```

## Fill handle

Drag the square at the bottom-right corner of the selection to fill neighbouring cells, or press `Ctrl` + `D` to fill down and `Ctrl` + `R` to fill right.

| Source | Result |
| --- | --- |
| A formula | Copied with relative references shifted, as in Excel. |
| Two or more numbers | The series continues along their linear trend: `10, 20` becomes `30, 40, 50`. |
| A single number | Copied. Hold `Ctrl` while releasing to count up instead: `1` becomes `2, 3, 4`. |
| A date | Continues one day at a time. |
| Text ending in a number | Counts up: `Unit 1` becomes `Unit 2`, `INV-0099` becomes `INV-0100`. |
| `Q1` | Continues `Q2, Q3, Q4, Q1`. |
| Month or weekday names | Continue in sequence, full or short: `Jan, Feb, Mar`, `Monday, Tuesday`. |
| Other text | Copied. |

Filled cells emit `cellChange` with the source `fill`.

## Clipboard

`Ctrl` + `C`, `Ctrl` + `X` and `Ctrl` + `V` work with the system clipboard:

- **Copy** puts the selection on the clipboard as tab-separated text and as an HTML table, so it pastes into Excel, Google Sheets, email or documents.
- **Paste within the same spreadsheet** keeps formulas, with relative references shifted to the new position, and styles.
- **Paste from other applications** reads HTML tables, including styles, or tab-separated text. Each cell is interpreted like typed input, so numbers, dates and formulas come through as such.
- **Cut and paste** moves the cells and updates every formula that referred to them.

A multiple selection can be copied when its ranges share their columns or their rows, as in Excel; other multiple selections cannot. Pasted cells emit `cellChange` with the source `paste`.

### Paste special

After copying inside the spreadsheet, `Ctrl` + `Alt` + `V`, **Home › Paste special** or the cell menu opens a dialog to paste only **values**, **formulas** or **formats**, optionally **transposed**:

```ts
sheet.pasteSpecial({ mode: 'values' });
sheet.pasteSpecial({ mode: 'formats' });
sheet.pasteSpecial({ mode: 'all', transpose: true });
```

Transposed formulas are pasted as their values.

### Paste values

`Ctrl` + `Shift` + `V`, **Home › Paste values** and **Paste values** in the cell menu paste what the cells show, without formulas and without formatting; the target cells keep their own format. For cells copied inside the spreadsheet the calculated values are pasted. For text from another application every cell is read like typed input and any formatting on the clipboard is ignored. In code: `sheet.pasteValues()`.

### Paste options

After every paste a small **Paste options** button appears at the lower corner of the pasted range. Its menu rewrites the paste you just made:

| Option | Result |
| --- | --- |
| Keep source formatting | Formulas, values and formats: the default paste. |
| Values only | Values without formulas or formats. |
| Formulas only | Formulas and values, the target keeps its formats. |
| Formatting only | Formats only, the target keeps its contents. |
| Transpose | Rows become columns; formulas are pasted as their values. |
| Keep source column widths | The default paste, and the target columns take the widths of the copied columns. |
| Paste link | Each target cell gets a formula that points at its source cell. |

The last two are offered for cells copied inside the spreadsheet. Choosing an option replaces the paste, so one undo removes it whichever option you ended on. The button leaves on the next edit or on `Escape`. From the keyboard, open the cell menu with `Shift` + `F10` and choose **Paste options…**. Set `pasteOptionsButton: false` to hide it. In code, `getPasteOptions()` returns `{ current, available }` while a paste can still be rewritten, and `applyPasteOption('values')` rewrites it.

### Format painter

**Home › Format painter** copies the formatting of the selection; the next range you select receives it. Double-click the button to keep painting until `Escape`. From the keyboard, `Ctrl` + `Alt` + `C` turns it on, and `Enter` applies it to the current selection. In code: `setFormatPainter(true)`, `setFormatPainter('locked')` and `setFormatPainter(false)`.

### Move by dragging

Drag the border of the selection to move the cells; formulas that refer to them follow. Hold `Ctrl` while dropping to copy instead. `Escape` cancels a drag. Double-clicking the fill handle fills down as far as the neighbouring column has data.

## Insert and delete cells

**Home → Insert cells** and **Delete cells**, the same two entries in the cell menu, and `Ctrl` + `Shift` + `=` and `Ctrl` + `-` on a selection of cells open a dialog with four choices: shift cells right or down (left or up when deleting), entire row, entire column. The dialog proposes the shift along the shorter side of the selection. With whole rows or columns selected the shortcuts insert or delete them directly, as before.

A shift moves only the cells in the columns of the selection (for down and up) or in its rows (for right and left); everything beside them stays where it is.

- **Formulas.** A reference that lies inside the moved columns or rows follows its cells, grows when cells are inserted inside it and shrinks when cells are deleted from it. A reference to cells that were deleted becomes `#REF!`. A reference that is wider than the selection is not changed. Defined names, chart series and sparkline ranges follow the same rules.
- **Formatting and rules.** Cell formats, notes, comments, links and pictures in cells move with their cells. Conditional formats and data validation are split where needed: the part inside the selection's columns moves, the rest stays.
- **Merged cells, tables and filters.** A merged cell, a table or a filtered range that lies completely inside the moved columns moves or grows with them. If the selection would cut one of them in two, nothing changes and the `error` event reports why; the same applies to a PivotTable or a data table in the way.
- **One step.** The whole change is one undo step.

```ts
sheet.insertCells('B3:C3', 'down');
sheet.deleteCells('B4:B9', 'left');
```

The headless engine has the same pair: `engine.insertCells(sheet, range, shift)` and `engine.deleteCells(sheet, range, shift)`; they throw when the range cuts a merged cell or a table.

## Undo and redo

`Ctrl` + `Z` undoes, `Ctrl` + `Y` or `Ctrl` + `Shift` + `Z` redoes, and `undo()`, `redo()`, `canUndo()` and `canRedo()` do the same in code. The history keeps 200 steps and covers edits, API changes, formatting, structure changes, sheet operations, rules and sorting. Loading a different workbook with `fromJSON()`, `importXlsx()` or `update({ data })` clears it.

## Keyboard shortcuts

`Cmd` replaces `Ctrl` on macOS.

| Keys | Action |
| --- | --- |
| Arrow keys | Move. With `Shift`, extend the selection; with `Ctrl`, jump to the edge of the data. |
| `Enter`, `Tab` | Commit and move down or right; `Shift` reverses. Inside a selection, move within it. |
| `F2`, double-click | Edit the cell in place. |
| `Escape` | Cancel editing, or clear the copy marquee. |
| `Delete` | Clear the selected cells, keeping their formatting. |
| `Backspace` | Clear the cell and start editing. |
| `Home`, `Ctrl` + `Home`, `Ctrl` + `End` | Go to column A, to the first cell after frozen panes, or to the last used cell. |
| `Page Up`, `Page Down` | Move one screen. `Ctrl` + `Page Up` / `Page Down` switches sheets. |
| `Ctrl` + `A` | Select the current data region, then the whole sheet. |
| `Shift` + `Space`, `Ctrl` + `Space` | Select whole rows or whole columns. |
| `Ctrl` + `Shift` + `+`, `Ctrl` + `-` | Insert or delete the selected rows or columns; on a selection of cells, open Insert cells or Delete cells. |
| `Ctrl` + `B`, `I`, `U`, `5` | Bold, italic, underline, strikethrough. |
| `Ctrl` + `D`, `Ctrl` + `R` | Fill down, fill right. |
| `Ctrl` + `;`, `Ctrl` + `Shift` + `;` | Insert today's date or the current time. |
| `Ctrl` + `F`, `Ctrl` + `H` | Find, find and replace. |
| `Ctrl` + `Shift` + `L` | Turn the autofilter on or off. |
| `Ctrl` + `Z`, `Ctrl` + `Y` | Undo, redo. |
| `Alt` + `Arrow Down` | Open the dropdown of a cell with a list validation. |
| `F4` while editing | Cycle `$` markers on the reference at the cursor. |
| `Shift` + `F10`, context menu key | Open the cell menu. |

In `readOnly` mode, users can select, copy and search, but not change anything; an attempt emits an `error` event with the code `readOnly`.

## Autofill series and custom lists

Dragging the fill handle continues a pattern like Excel does. Numbers and dates follow a linear trend. Text with a trailing number counts up (`Item 9`, `Item 10`). These also continue:

- day and month names, full or short: `Monday`, `Mon`, `January`, `Jan`
- quarters: `Q1`, `Qtr 1`, `Quarter 1`, `Q3 2026` (which rolls over to `Q1 2027`)
- month and year labels: `Nov 2026`, `Dec 2026`, `Jan 2027`
- ordinals: `1st`, `2nd`, `3rd`, `4th`, `11th`
- fiscal labels such as `FY2026`

The case of the first cell is kept. Add lists of your own with the `customLists` option. A cell that matches an item in a list continues through that list and wraps around:

```ts
createSpreadsheet(el, {
  customLists: [
    ['North', 'East', 'South', 'West'],
    ['Draft', 'Review', 'Approved', 'Published'],
  ],
});
```

`Ctrl` + `D` and `Ctrl` + `R` copy rather than continue a series, as in Excel.
