# Workbook

> Language fallback: requested `zh-CN`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/zh-CN/reference/facade/workbook](https://docs.univer.ai/zh-CN/reference/facade/workbook)

- Agent Markdown: [https://docs.univer.ai/zh-CN/reference/facade/workbook.md](https://docs.univer.ai/zh-CN/reference/facade/workbook.md)

- Requested language: `zh-CN`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/workbook.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/workbook.mdx)

---

| Packages | `@univerjs/sheets-ui`, `@univerjs-pro/sheets-pivot`, `@univerjs/sheets`, `@univerjs/sheets-table`, `@univerjs/sheets-thread-comment`, `@univerjs-pro/sheets-print`, `@univerjs-pro/range-preprocess`, `@univerjs/sheets-data-validation`, `@univerjs/sheets-formula`, `@univerjs/sheets-hyper-link-ui`, `@univerjs/sheets-hyper-link`, `@univerjs/sheets-numfmt` |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Facade API object bounded to a workbook. It provides a set of methods to interact with the workbook.

> This class should not be instantiated directly. Use factory methods on `univerAPI` instead.

## Overview

### @univerjs/sheets

| Method                                                  | Description                                                                                           |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [`addStyles`](#addstyles)                               | Add styles to the workbook styles                                                                     |
| [`create`](#create)                                     | Create a new worksheet and returns a handle to it                                                     |
| [`createRangeThemeStyle`](#createrangethemestyle)       | Create a range theme style                                                                            |
| [`deleteActiveSheet`](#deleteactivesheet)               | Deletes the currently active sheet                                                                    |
| [`deleteDefinedName`](#deletedefinedname)               | Delete the defined name with the given name                                                           |
| [`deleteSheet`](#deletesheet)                           | Deletes the specified worksheet                                                                       |
| [`dispose`](#dispose)                                   | -                                                                                                     |
| [`duplicateActiveSheet`](#duplicateactivesheet)         | Duplicates the active sheet                                                                           |
| [`duplicateSheet`](#duplicatesheet)                     | Duplicates the given worksheet                                                                        |
| [`getActiveCell`](#getactivecell)                       | Returns the active cell in this spreadsheet                                                           |
| [`getActiveRange`](#getactiverange)                     | Returns the selected range in the active sheet, or null if there is no active range                   |
| [`getActiveSheet`](#getactivesheet)                     | Get the active sheet of the workbook                                                                  |
| [`getCustomMetadata`](#getcustommetadata)               | Get custom metadata of workbook                                                                       |
| [`getDefinedName`](#getdefinedname)                     | Get the defined name by name                                                                          |
| [`getDefinedNames`](#getdefinednames)                   | Get all the defined names in the workbook                                                             |
| [`getId`](#getid)                                       | Get the id of the workbook                                                                            |
| [`getLocale`](#getlocale)                               | Get the locale of the workbook                                                                        |
| [`getName`](#getname)                                   | Get the name of the workbook                                                                          |
| [`getNumSheets`](#getnumsheets)                         | Get the number of sheets in the workbook                                                              |
| [`getRegisteredRangeThemes`](#getregisteredrangethemes) | Gets the registered range themes                                                                      |
| [`getSheetByName`](#getsheetbyname)                     | Get a worksheet by sheet name                                                                         |
| [`getSheetBySheetId`](#getsheetbysheetid)               | Get a worksheet by sheet id                                                                           |
| [`getSheets`](#getsheets)                               | Gets all the worksheets in this workbook                                                              |
| [`getSnapshot`](#getsnapshot)                           | -                                                                                                     |
| [`getUrl`](#geturl)                                     | Get the URL of the workbook                                                                           |
| [`getWorkbook`](#getworkbook)                           | Get the Workbook instance                                                                             |
| [`getWorkbookPermission`](#getworkbookpermission)       | Get the WorkbookPermission instance for managing workbook-level permissions                           |
| [`id`](#id)                                             | -                                                                                                     |
| [`insertDefinedName`](#insertdefinedname)               | Insert a defined name                                                                                 |
| [`insertDefinedNameBuilder`](#insertdefinednamebuilder) | Insert a defined name by builder param                                                                |
| [`insertSheet`](#insertsheet)                           | Inserts a new worksheet into the workbook                                                             |
| [`moveActiveSheet`](#moveactivesheet)                   | Move the active sheet to the specified index                                                          |
| [`moveSheet`](#movesheet)                               | Move the sheet to the specified index                                                                 |
| [`newDefinedNameBuilder`](#newdefinednamebuilder)       | Create a new defined name builder                                                                     |
| [`onBeforeCommandExecute`](#onbeforecommandexecute)     | Callback for command execution                                                                        |
| [`onCommandExecuted`](#oncommandexecuted)               | Callback for command execution                                                                        |
| [`onSelectionChange`](#onselectionchange)               | Callback for selection changes                                                                        |
| [`redo`](#redo)                                         | Redo the last undone action                                                                           |
| [`registerRangeTheme`](#registerrangetheme)             | Register a custom range theme style                                                                   |
| [`removeStyles`](#removestyles)                         | Remove styles from the workbook styles                                                                |
| [`save`](#save)                                         | Save workbook snapshot data, including conditional formatting, data validation, and other plugin data |
| [`setActiveRange`](#setactiverange)                     | Sets the selection region for active sheet                                                            |
| [`setActiveSheet`](#setactivesheet)                     | Sets the given worksheet to be the active worksheet in the workbook                                   |
| [`setCustomMetadata`](#setcustommetadata)               | Set custom metadata of workbook                                                                       |
| [`setEditable`](#seteditable)                           | Used to modify the editing permissions of the workbook                                                |
| [`setLocale`](#setlocale)                               | -                                                                                                     |
| [`setName`](#setname)                                   | Set the name of the workbook                                                                          |
| [`setSpreadsheetLocale`](#setspreadsheetlocale)         | Set the locale of the workbook                                                                        |
| [`undo`](#undo)                                         | Undo the last action                                                                                  |
| [`unregisterRangeTheme`](#unregisterrangetheme)         | Unregister a custom range theme style                                                                 |
| [`updateDefinedNameBuilder`](#updatedefinednamebuilder) | Update the defined name with the given name                                                           |

### @univerjs/sheets-data-validation

| Method                                                                          | Description |
| ------------------------------------------------------------------------------- | ----------- |
| [`getAllDataValidationErrorAsync`](#getalldatavalidationerrorasync)             | -           |
| [`getValidatorStatus`](#getvalidatorstatus)                                     | -           |
| [`onBeforeAddDataValidation`](#onbeforeadddatavalidation)                       | -           |
| [`onBeforeDeleteAllDataValidation`](#onbeforedeletealldatavalidation)           | -           |
| [`onBeforeDeleteDataValidation`](#onbeforedeletedatavalidation)                 | -           |
| [`onBeforeUpdateDataValidationCriteria`](#onbeforeupdatedatavalidationcriteria) | -           |
| [`onBeforeUpdateDataValidationOptions`](#onbeforeupdatedatavalidationoptions)   | -           |
| [`onBeforeUpdateDataValidationRange`](#onbeforeupdatedatavalidationrange)       | -           |

### @univerjs/sheets-formula

| Method                                      | Description                            |
| ------------------------------------------- | -------------------------------------- |
| [`getAllFormulaError`](#getallformulaerror) | Get all formula errors in the workbook |

### @univerjs/sheets-hyper-link

| Method                                        | Description                                          |
| --------------------------------------------- | ---------------------------------------------------- |
| [`getUrlOfDefineName`](#geturlofdefinename)   | Create a hyperlink url for the defined name          |
| [`parseSheetHyperlink`](#parsesheethyperlink) | Parse the hyperlink string to get the hyperlink info |

### @univerjs/sheets-hyper-link-ui

| Method                                                  | Description                         |
| ------------------------------------------------------- | ----------------------------------- |
| [`navigateToSheetHyperlink`](#navigatetosheethyperlink) | Navigate to the specified hyperlink |

### @univerjs/sheets-numfmt

| Method                              | Description                              |
| ----------------------------------- | ---------------------------------------- |
| [`setNumfmtLocal`](#setnumfmtlocal) | Set the locale for number format display |

### @univerjs/sheets-table

| Method                                      | Description |
| ------------------------------------------- | ----------- |
| [`addTable`](#addtable)                     | -           |
| [`getTableInfo`](#gettableinfo)             | -           |
| [`getTableInfoByName`](#gettableinfobyname) | -           |
| [`getTableList`](#gettablelist)             | -           |
| [`removeTable`](#removetable)               | -           |
| [`setTableFilter`](#settablefilter)         | -           |

### @univerjs/sheets-thread-comment

| Method                            | Description |
| --------------------------------- | ----------- |
| [`clearComments`](#clearcomments) | -           |
| [`getComments`](#getcomments)     | -           |

### @univerjs/sheets-ui

| Method                                                      | Description                         |
| ----------------------------------------------------------- | ----------------------------------- |
| [`abortEditingAsync`](#aborteditingasync)                   | -                                   |
| [`customizeColumnHeader`](#customizecolumnheader)           | -                                   |
| [`customizeRowHeader`](#customizerowheader)                 | -                                   |
| [`disableSelection`](#disableselection)                     | -                                   |
| [`enableSelection`](#enableselection)                       | -                                   |
| [`endEditing`](#endediting)                                 | -                                   |
| [`endEditingAsync`](#endeditingasync)                       | -                                   |
| [`getScrollStateBySheetId`](#getscrollstatebysheetid)       | Get scroll state of specified sheet |
| [`isCellEditing`](#iscellediting)                           | -                                   |
| [`onCellClick`](#oncellclick)                               | -                                   |
| [`onCellHover`](#oncellhover)                               | -                                   |
| [`onCellPointerDown`](#oncellpointerdown)                   | -                                   |
| [`onCellPointerMove`](#oncellpointermove)                   | -                                   |
| [`onCellPointerUp`](#oncellpointerup)                       | -                                   |
| [`onDragOver`](#ondragover)                                 | -                                   |
| [`onDrop`](#ondrop)                                         | -                                   |
| [`setPermissionDialogVisible`](#setpermissiondialogvisible) | -                                   |
| [`showSelection`](#showselection)                           | -                                   |
| [`startEditing`](#startediting)                             | -                                   |
| [`transparentSelection`](#transparentselection)             | -                                   |

### @univerjs-pro/sheets-pivot

| Method                                        | Description |
| --------------------------------------------- | ----------- |
| [`addPivotTable`](#addpivottable)             | -           |
| [`getPivotTableByCell`](#getpivottablebycell) | -           |
| [`getPivotTableById`](#getpivottablebyid)     | -           |

### @univerjs-pro/sheets-print

| Method                                                    | Description |
| --------------------------------------------------------- | ----------- |
| [`closePrintDialog`](#closeprintdialog)                   | -           |
| [`openPrintDialog`](#openprintdialog)                     | -           |
| [`print`](#print)                                         | -           |
| [`saveScreenshotToClipboard`](#savescreenshottoclipboard) | -           |
| [`updatePrintConfig`](#updateprintconfig)                 | -           |
| [`updatePrintRenderConfig`](#updateprintrenderconfig)     | -           |

### @univerjs-pro/range-preprocess

| Method                                        | Description                          |
| --------------------------------------------- | ------------------------------------ |
| [`getPreprocessRanges`](#getpreprocessranges) | Get all preprocess range information |

## APIs

### Sheet Operations

### `create`

Create a new worksheet and returns a handle to it.

**Signature**

```typescript
create(name: string, rows: number, columns: number, options?: { index?: number; sheet?: Partial<IWorksheetData> }): FWorksheet
```

**Parameters**

* `name` `string` — *No description*
* `rows` `number` — *No description*
* `columns` `number` — *No description*
* `options` `{ index?: number; sheet?: Partial<IWorksheetData>; }` *(optional)* — *No description*

**Returns**

* `FWorksheet` — The new created sheet

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();

// Create a new sheet named 'MyNewSheet' with 10 rows and 10 columns
const newSheet = fWorkbook.create('MyNewSheet', 10, 10);
console.log(newSheet);

// Create a new sheet named 'MyNewSheetWithData' with 10 rows and 10 columns and some data, and set it as the first sheet
const sheetData = {
  // ... Omit other properties
  cellData: {
    0: {
      0: {
        v: 'Hello Univer!',
      }
    }
  },
  // ... Omit other properties
};
const newSheetWithData = fWorkbook.create('MyNewSheetWithData', 10, 10, {
  index: 0,
  sheet: sheetData,
});
console.log(newSheetWithData);
```

Source: 

`@univerjs/sheets`

### `createRangeThemeStyle`

Create a range theme style.

**Signature**

```typescript
createRangeThemeStyle(themeName: string, themeStyleJson?: Omit<IRangeThemeStyleJSON, 'name'>): RangeThemeStyle
```

**Parameters**

* `themeName` `string` — *No description*
* `themeStyleJson` `Omit<IRangeThemeStyleJSON, "name">` *(optional)* — *No description*

**Returns**

* `RangeThemeStyle` — - The created range theme style

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const rangeThemeStyle = fWorkbook.createRangeThemeStyle('MyTheme', {
  secondRowStyle: {
    bg: {
      rgb: 'rgb(214,231,241)',
    },
  },
});
console.log(rangeThemeStyle);
```

Source: 

`@univerjs/sheets`

### `deleteActiveSheet`

Deletes the currently active sheet.

**Signature**

```typescript
deleteActiveSheet(): boolean
```

**Returns**

* `boolean` — true if the sheet was deleted, false otherwise

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.deleteActiveSheet();
```

Source: 

`@univerjs/sheets`

### `deleteDefinedName`

Delete the defined name with the given name.

**Signature**

```typescript
deleteDefinedName(name: string): boolean
```

**Parameters**

* `name` `string` — *No description*

**Returns**

* `boolean` — true if the defined name was deleted, false otherwise

**Examples**

```ts
// The code below deletes the defined name with the given name
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.deleteDefinedName('MyDefinedName');
```

Source: 

`@univerjs/sheets`

### `deleteSheet`

Deletes the specified worksheet.

**Signature**

```typescript
deleteSheet(sheet: FWorksheet | string): boolean
```

**Parameters**

* `sheet` `string | FWorksheet` — *No description*

**Returns**

* `boolean` — True if the worksheet was deleted, false otherwise.

**Examples**

```ts
// The code below deletes the specified worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheets()[1];
fWorkbook.deleteSheet(sheet);

// The code below deletes the specified worksheet by id
// fWorkbook.deleteSheet(sheet.getSheetId());
```

Source: 

`@univerjs/sheets`

### `getActiveSheet`

Get the active sheet of the workbook.

**Signature**

```typescript
getActiveSheet(): FWorksheet
```

**Returns**

* `FWorksheet` — The active sheet of the workbook

**Examples**

```ts
// The code below gets the active sheet of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
console.log(fWorksheet);
```

Source: 

`@univerjs/sheets`

### `getSheetByName`

Get a worksheet by sheet name.

**Signature**

```typescript
getSheetByName(name: string): FWorksheet | null
```

**Parameters**

* `name` `string` — *No description*

**Returns**

* `FWorksheet` — The worksheet with given sheet name

**Examples**

```ts
// The code below gets a worksheet by sheet name
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheetByName('Sheet1');
console.log(sheet);
```

Source: 

`@univerjs/sheets`

### `getSheetBySheetId`

Get a worksheet by sheet id.

**Signature**

```typescript
getSheetBySheetId(sheetId: string): FWorksheet | null
```

**Parameters**

* `sheetId` `string` — *No description*

**Returns**

* `FWorksheet` — The worksheet with given sheet id

**Examples**

```ts
// The code below gets a worksheet by sheet id
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheetBySheetId('sheetId');
console.log(sheet);
```

Source: 

`@univerjs/sheets`

### `getSheets`

Gets all the worksheets in this workbook

**Signature**

```typescript
getSheets(): FWorksheet[]
```

**Returns**

* `FWorksheet[]` — An array of all the worksheets in the workbook

**Examples**

```ts
// The code below gets all the worksheets in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const sheets = fWorkbook.getSheets();
console.log(sheets);
```

Source: 

`@univerjs/sheets`

### `insertDefinedName`

Insert a defined name.

**Signature**

```typescript
insertDefinedName(name: string, formulaOrRefString: string): FWorkbook
```

**Parameters**

* `name` `string` — *No description*
* `formulaOrRefString` `string` — *No description*

**Returns**

* `FWorkbook` — The current FWorkbook instance

**Examples**

```ts
// The code below inserts a defined name
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.insertDefinedName('MyDefinedName', 'Sheet1!$A$1');
```

Source: 

`@univerjs/sheets`

### `insertDefinedNameBuilder`

Insert a defined name by builder param.

**Signature**

```typescript
insertDefinedNameBuilder(param: ISetDefinedNameMutationParam): void
```

**Parameters**

* `param` `ISetDefinedNameMutationParam` — *No description*

**Examples**

```ts
// The code below inserts a defined name by builder param
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameParam = fWorkbook.newDefinedNameBuilder()
  .setRef('Sheet1!$A$1')
  .setName('MyDefinedName')
  .setComment('This is a comment')
  .build();
fWorkbook.insertDefinedNameBuilder(definedNameParam);
```

Source: 

`@univerjs/sheets`

### `newDefinedNameBuilder`

Create a new defined name builder.

**Signature**

```typescript
newDefinedNameBuilder(): FDefinedNameBuilder
```

**Returns**

* `FDefinedNameBuilder` — The defined name builder.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameParam = fWorkbook.newDefinedNameBuilder()
  .setRef('Sheet1!$A$1')
  .setName('MyDefinedName')
  .setComment('This is a comment')
  .build();
console.log(definedNameParam);
fWorkbook.insertDefinedNameBuilder(definedNameParam);
```

Source: 

`@univerjs/sheets`

### `insertSheet`

Inserts a new worksheet into the workbook.
Using a default sheet name. The new sheet becomes the active sheet

**Signature**

```typescript
insertSheet(sheetName?: string, options?: { index?: number; sheet?: Partial<IWorksheetData> }): FWorksheet
```

**Parameters**

* `sheetName` `string` *(optional)* — *No description*
* `options` `{ index?: number; sheet?: Partial<IWorksheetData>; }` *(optional)* — *No description*

**Returns**

* `FWorksheet` — The new sheet

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();

// Create a new sheet with default configuration
const newSheet = fWorkbook.insertSheet();
console.log(newSheet);

// Create a new sheet with custom name and default configuration
const newSheetWithName = fWorkbook.insertSheet('MyNewSheet');
console.log(newSheetWithName);

// Create a new sheet with custom name and custom configuration
const sheetData = {
  // ... Omit other properties
  cellData: {
    0: {
      0: {
        v: 'Hello Univer!',
      }
    }
  },
  // ... Omit other properties
};
const newSheetWithData = fWorkbook.insertSheet('MyNewSheetWithData', {
  index: 0,
  sheet: sheetData,
});
console.log(newSheetWithData);
```

Source: 

`@univerjs/sheets`

### Defined Names

### `getDefinedName`

Get the defined name by name.

**Signature**

```typescript
getDefinedName(name: string): FDefinedName | null
```

**Parameters**

* `name` `string` — *No description*

**Returns**

* `FDefinedName` — The defined name with the given name

**Examples**

```ts
// The code below gets the defined name by name
const fWorkbook = univerAPI.getActiveWorkbook();
const definedName = fWorkbook.getDefinedName('MyDefinedName');
console.log(definedName?.getFormulaOrRefString());
```

Source: 

`@univerjs/sheets`

### `getDefinedNames`

Get all the defined names in the workbook.

**Signature**

```typescript
getDefinedNames(): FDefinedName[]
```

**Returns**

* `FDefinedName[]` — All the defined names in the workbook

**Examples**

```ts
// The code below gets all the defined names in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNames = fWorkbook.getDefinedNames();
console.log(definedNames, definedNames[0]?.getFormulaOrRefString());
```

Source: 

`@univerjs/sheets`

### `getName`

Get the name of the workbook.

**Signature**

```typescript
getName(): string
```

**Returns**

* `string` — The name of the workbook.

**Examples**

```ts
// The code below gets the name of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const name = fWorkbook.getName();
console.log(name);
```

Source: 

`@univerjs/sheets`

### `getTableInfoByName`

**Signature**

```typescript
getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined
```

**Parameters**

* `tableName` `string` — *No description*

**Returns**

* `any` — See signature above.

Source: 

`@univerjs/sheets-table`

### `setName`

Set the name of the workbook.

**Signature**

```typescript
setName(name: string): this
```

**Parameters**

* `name` `string` — *No description*

**Returns**

* `this` — See signature above.

**Examples**

```ts
// The code below sets the name of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setName('MyWorkbook');
```

Source: 

`@univerjs/sheets`

### `updateDefinedNameBuilder`

Update the defined name with the given name.

**Signature**

```typescript
updateDefinedNameBuilder(param: ISetDefinedNameMutationParam): void
```

**Parameters**

* `param` `ISetDefinedNameMutationParam` — *No description*

**Examples**

```ts
// The code below updates the defined name with the given name
const fWorkbook = univerAPI.getActiveWorkbook();
const definedName = fWorkbook.getDefinedName('MyDefinedName');
console.log(definedName?.getFormulaOrRefString());

// Update the defined name
if (definedName) {
  const newDefinedNameParam = definedName.toBuilder()
    .setName('NewDefinedName')
    .setRef('Sheet1!$A$2')
    .build();
  fWorkbook.updateDefinedNameBuilder(newDefinedNameParam);
}
```

Source: 

`@univerjs/sheets`

### Range Themes

### `getRegisteredRangeThemes`

Gets the registered range themes.

**Signature**

```typescript
getRegisteredRangeThemes(): string[]
```

**Returns**

* `string[]` — The name list of registered range themes.

**Examples**

```ts
// The code below gets the registered range themes
const fWorkbook = univerAPI.getActiveWorkbook();
const themes = fWorkbook.getRegisteredRangeThemes();
console.log(themes);
```

Source: 

`@univerjs/sheets`

### `registerRangeTheme`

Register a custom range theme style.

**Signature**

```typescript
registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void
```

**Parameters**

* `rangeThemeStyle` `RangeThemeStyle` — *No description*

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const rangeThemeStyle = fWorkbook.createRangeThemeStyle('MyTheme', {
  secondRowStyle: {
    bg: {
      rgb: 'rgb(214,231,241)',
    },
  },
});
fWorkbook.registerRangeTheme(rangeThemeStyle);
```

Source: 

`@univerjs/sheets`

### `unregisterRangeTheme`

Unregister a custom range theme style.

**Signature**

```typescript
unregisterRangeTheme(themeName: string): void
```

**Parameters**

* `themeName` `string` — *No description*

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.unregisterRangeTheme('MyTheme');
```

Source: 

`@univerjs/sheets`

### Range Preprocess

### `getPreprocessRanges`

Get all preprocess range information.

**Signature**

```typescript
getPreprocessRanges(responseDataMode?: string): Record<string, ITableJson[]>
```

**Parameters**

* `responseDataMode` `string` *(optional)* — The response data mode.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook()
const preprocessRanges = fWorkbook.getPreprocessRanges()
```

Source: 

`@univerjs-pro/range-preprocess`

### Collaboration

### `getSnapshot`

> [!WARN]
> Deprecated — use 'save' instead.

**Signature**

```typescript
getSnapshot(): IWorkbookData
```

**Returns**

* `IWorkbookData` — Workbook snapshot data

**Tags**

* `@memberof` — FWorkbook

**Examples**

```ts
// The code below saves the workbook snapshot data
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const snapshot = activeSpreadsheet.getSnapshot();
```

Source: 

`@univerjs/sheets`

### Pivot Tables

### `addPivotTable`

**Signature**

```typescript
async addPivotTable(sourceInfo: IUnitRangeName & { subUnitId: string }, positionType: PositionType, anchorCellInfo: IPivotCellPositionInfo): Promise<FPivotTable | undefined>
```

**Parameters**

* `sourceInfo` `any` — *No description*
* `positionType` `PositionType` — *No description*
* `anchorCellInfo` `IPivotCellPositionInfo` — *No description*

**Returns**

* `Promise<FPivotTable>` — See signature above.

Source: 

`@univerjs-pro/sheets-pivot`

### `getPivotTableByCell`

**Signature**

```typescript
getPivotTableByCell(unitId: string, subUnitId: string, row: number, col: number): FPivotTable | undefined
```

**Parameters**

* `unitId` `string` — *No description*
* `subUnitId` `string` — *No description*
* `row` `number` — *No description*
* `col` `number` — *No description*

**Returns**

* `FPivotTable` — See signature above.

Source: 

`@univerjs-pro/sheets-pivot`

### `getPivotTableById`

**Signature**

```typescript
getPivotTableById(pivotTableId: string): FPivotTable | undefined
```

**Parameters**

* `pivotTableId` `string` — *No description*

**Returns**

* `FPivotTable` — See signature above.

Source: 

`@univerjs-pro/sheets-pivot`

### Miscellaneous

### `abortEditingAsync`

**Signature**

```typescript
abortEditingAsync(): Promise<boolean>
```

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `addStyles`

Add styles to the workbook styles.

**Signature**

```typescript
addStyles(styles: Record<string, IStyleData>): void
```

**Parameters**

* `styles` `Record<string, IStyleData>` — *No description*

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();

// Add styles to the workbook styles
const styles = {
  'custom-style-1': {
    bg: {
      rgb: 'rgb(255, 0, 0)',
    }
  },
  'custom-style-2': {
    fs: 20,
    n: {
      pattern: '@'
    }
  }
};
fWorkbook.addStyles(styles);

// Set values with the new styles
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValues([
  [{ v: 'Hello', s: 'custom-style-1' }, { v: 'Univer', s: 'custom-style-1' }],
  [{ v: 'To', s: 'custom-style-1' }, { v: '0001', s: 'custom-style-2' }],
]);
```

Source: 

`@univerjs/sheets`

### `clearComments`

**Signature**

```typescript
clearComments(): Promise<boolean>
```

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-thread-comment`

### `customizeColumnHeader`

**Signature**

```typescript
customizeColumnHeader(cfg: IColumnsHeaderCfgParam): void
```

**Parameters**

* `cfg` `IColumnsHeaderCfgParam` — *No description*

Source: 

`@univerjs/sheets-ui`

### `customizeRowHeader`

**Signature**

```typescript
customizeRowHeader(cfg: IRowsHeaderCfgParam): void
```

**Parameters**

* `cfg` `IRowsHeaderCfgParam` — *No description*

Source: 

`@univerjs/sheets-ui`

### `disableSelection`

**Signature**

```typescript
disableSelection(): FWorkbook
```

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `dispose`

**Signature**

```typescript
dispose(): void
```

Source: 

`@univerjs/sheets`

### `duplicateActiveSheet`

Duplicates the active sheet.

**Signature**

```typescript
duplicateActiveSheet(): FWorksheet
```

**Returns**

* `FWorksheet` — The duplicated worksheet

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const duplicatedSheet = fWorkbook.duplicateActiveSheet();
console.log(duplicatedSheet);
```

Source: 

`@univerjs/sheets`

### `duplicateSheet`

Duplicates the given worksheet.

**Signature**

```typescript
duplicateSheet(sheet: FWorksheet): FWorksheet
```

**Parameters**

* `sheet` `FWorksheet` — *No description*

**Returns**

* `FWorksheet` — The duplicated worksheet

**Examples**

```ts
// The code below duplicates the given worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const activeSheet = fWorkbook.getActiveSheet();
const duplicatedSheet = fWorkbook.duplicateSheet(activeSheet);
console.log(duplicatedSheet);
```

Source: 

`@univerjs/sheets`

### `enableSelection`

**Signature**

```typescript
enableSelection(): FWorkbook
```

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `endEditing`

**Signature**

```typescript
async endEditing(save?: boolean): Promise<boolean>
```

**Parameters**

* `save` `boolean` *(optional)* — *No description*

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `endEditingAsync`

**Signature**

```typescript
endEditingAsync(save = true): Promise<boolean>
```

**Parameters**

* `save` `boolean` *(optional)* — *No description*

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `getActiveCell`

Returns the active cell in this spreadsheet.

**Signature**

```typescript
getActiveCell(): FRange | null
```

**Returns**

* `FRange` — The active cell

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getActiveCell().getA1Notation());
```

Source: 

`@univerjs/sheets`

### `getActiveRange`

Returns the selected range in the active sheet, or null if there is no active range.

**Signature**

```typescript
getActiveRange(): FRange | null
```

**Returns**

* `FRange` — The active range

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const activeRange = fWorkbook.getActiveRange();
console.log(activeRange);
```

Source: 

`@univerjs/sheets`

### `getAllDataValidationErrorAsync`

**Signature**

```typescript
async getAllDataValidationErrorAsync(): Promise<IDataValidationError[]>
```

**Returns**

* `Promise<IDataValidationError[]>` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `getAllFormulaError`

Get all formula errors in the workbook.

**Signature**

```typescript
getAllFormulaError(): ISheetFormulaError[]
```

**Returns**

* `ISheetFormulaError[]` — Array of formula errors.

Source: 

`@univerjs/sheets-formula`

### `getComments`

**Signature**

```typescript
getComments(): FThreadComment[]
```

**Returns**

* `FThreadComment[]` — See signature above.

Source: 

`@univerjs/sheets-thread-comment`

### `getCustomMetadata`

Get custom metadata of workbook

**Signature**

```typescript
getCustomMetadata(): CustomData | undefined
```

**Returns**

* `CustomData` — custom metadata

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const custom = fWorkbook.getCustomMetadata();
console.log(custom);
```

Source: 

`@univerjs/sheets`

### `getId`

Get the id of the workbook.

**Signature**

```typescript
getId(): string
```

**Returns**

* `string` — The id of the workbook.

**Examples**

```ts
// The code below gets the id of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook.getId();
console.log(unitId);
```

Source: 

`@univerjs/sheets`

### `getLocale`

Get the locale of the workbook.

**Signature**

```typescript
getLocale(): LocaleType
```

**Returns**

* `LocaleType` — The locale of the workbook

**Examples**

```ts
// The code below gets the locale of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getLocale());
```

Source: 

`@univerjs/sheets`

### `getNumSheets`

Get the number of sheets in the workbook.

**Signature**

```typescript
getNumSheets(): number
```

**Returns**

* `number` — The number of sheets in the workbook

**Examples**

```ts
// The code below gets the number of sheets in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getNumSheets());
```

Source: 

`@univerjs/sheets`

### `getScrollStateBySheetId`

Get scroll state of specified sheet.

**Signature**

```typescript
getScrollStateBySheetId(sheetId: string): Nullable<IScrollState>
```

**Parameters**

* `sheetId` `string` — *No description*

**Returns**

* `any` — scroll state

**Examples**

```ts
 ts
univerAPI.getActiveWorkbook().getScrollStateBySheetId($sheetId)
```

Source: 

`@univerjs/sheets-ui`

### `getUrl`

Get the URL of the workbook.

**Signature**

```typescript
getUrl(): string
```

**Returns**

* `string` — The URL of the workbook

**Examples**

```ts
// The code below gets the URL of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const url = fWorkbook.getUrl();
console.log(url);
```

Source: 

`@univerjs/sheets`

### `getValidatorStatus`

**Signature**

```typescript
getValidatorStatus(): Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>
```

**Returns**

* `Promise<Record<string, ObjectMatrix<Nullable<DataValidationStatus>>>>` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `getWorkbook`

Get the Workbook instance.

**Signature**

```typescript
getWorkbook(): Workbook
```

**Returns**

* `Workbook` — The Workbook instance.

**Examples**

```ts
// The code below gets the Workbook instance
const fWorkbook = univerAPI.getActiveWorkbook();
const workbook = fWorkbook.getWorkbook();
console.log(workbook);
```

Source: 

`@univerjs/sheets`

### `getWorkbookPermission`

Get the WorkbookPermission instance for managing workbook-level permissions.
This is the new permission API that provides a more intuitive and type-safe interface.

**Signature**

```typescript
getWorkbookPermission(): FWorkbookPermission
```

**Returns**

* `FWorkbookPermission` — - The WorkbookPermission instance.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getWorkbookPermission();

// Set workbook to read-only mode
await permission.setMode('viewer');

// Add a collaborator
await permission.addCollaborator({
  userId: 'user123',
  name: 'John Doe',
  role: 'editor'
});

// Subscribe to permission changes
permission.permission$.subscribe(snapshot => {
  console.log('Permissions changed:', snapshot);
});
```

Source: 

`@univerjs/sheets`

### `id`

**Signature**

```typescript
id: string
```

**Returns**

* `string` — See signature above.

Source: 

`@univerjs/sheets`

### `isCellEditing`

**Signature**

```typescript
isCellEditing(): boolean
```

**Returns**

* `boolean` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `moveActiveSheet`

Move the active sheet to the specified index.

**Signature**

```typescript
moveActiveSheet(index: number): FWorkbook
```

**Parameters**

* `index` `number` — *No description*

**Returns**

* `FWorkbook` — This workbook, for chaining

**Examples**

```ts
// The code below moves the active sheet to the specified index
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.moveActiveSheet(1);
```

Source: 

`@univerjs/sheets`

### `moveSheet`

Move the sheet to the specified index.

**Signature**

```typescript
moveSheet(sheet: FWorksheet, index: number): FWorkbook
```

**Parameters**

* `sheet` `FWorksheet` — *No description*
* `index` `number` — *No description*

**Returns**

* `FWorkbook` — This workbook, for chaining

**Examples**

```ts
// The code below moves the sheet to the specified index
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getActiveSheet();
fWorkbook.moveSheet(sheet, 1);
```

Source: 

`@univerjs/sheets`

### `navigateToSheetHyperlink`

Navigate to the specified hyperlink within the workbook.

**Signature**

```typescript
navigateToSheetHyperlink(hyperlink: string): void
```

**Parameters**

* `hyperlink` `string` — The hyperlink string to navigate to.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.navigateToSheetHyperlink('#gid=sheet1&range=A1');
```

Source: 

`@univerjs/sheets-hyper-link-ui`

### `onBeforeAddDataValidation`

**Signature**

```typescript
onBeforeAddDataValidation(callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IAddSheetDataValidationCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onBeforeCommandExecute`

Callback for command execution.

**Signature**

```typescript
onBeforeCommandExecute(callback: CommandListener): IDisposable
```

**Parameters**

* `callback` `CommandListener` — *No description*

**Returns**

* `IDisposable` — See signature above.

**Tags**

* `@callback` — onBeforeCommandExecuteCallback

Source: 

`@univerjs/sheets`

### `onBeforeDeleteAllDataValidation`

**Signature**

```typescript
onBeforeDeleteAllDataValidation(callback: (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onBeforeDeleteDataValidation`

**Signature**

```typescript
onBeforeDeleteDataValidation(callback: (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onBeforeUpdateDataValidationCriteria`

**Signature**

```typescript
onBeforeUpdateDataValidationCriteria(callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onBeforeUpdateDataValidationOptions`

**Signature**

```typescript
onBeforeUpdateDataValidationOptions(callback: (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onBeforeUpdateDataValidationRange`

**Signature**

```typescript
onBeforeUpdateDataValidationRange(callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable
```

**Parameters**

* `callback` `(params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions) => false | void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-data-validation`

### `onCellClick`

**Signature**

```typescript
onCellClick(callback: (cell: IHoverRichTextInfo) => void): IDisposable
```

**Parameters**

* `callback` `(cell: IHoverRichTextInfo) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onCellHover`

**Signature**

```typescript
onCellHover(callback: (cell: IHoverRichTextPosition) => void): IDisposable
```

**Parameters**

* `callback` `(cell: IHoverRichTextPosition) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onCellPointerDown`

**Signature**

```typescript
onCellPointerDown(callback: (cell: ICellPosWithEvent) => void): IDisposable
```

**Parameters**

* `callback` `(cell: ICellPosWithEvent) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onCellPointerMove`

**Signature**

```typescript
onCellPointerMove(callback: (cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => void): IDisposable
```

**Parameters**

* `callback` `(cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onCellPointerUp`

**Signature**

```typescript
onCellPointerUp(callback: (cell: ICellPosWithEvent) => void): IDisposable
```

**Parameters**

* `callback` `(cell: ICellPosWithEvent) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onCommandExecuted`

Callback for command execution.

**Signature**

```typescript
onCommandExecuted(callback: CommandListener): IDisposable
```

**Parameters**

* `callback` `CommandListener` — *No description*

**Returns**

* `IDisposable` — See signature above.

**Tags**

* `@callback` — onCommandExecutedCallback

Source: 

`@univerjs/sheets`

### `onDragOver`

**Signature**

```typescript
onDragOver(callback: (cell: IDragCellPosition) => void): IDisposable
```

**Parameters**

* `callback` `(cell: IDragCellPosition) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onDrop`

**Signature**

```typescript
onDrop(callback: (cell: IDragCellPosition) => void): IDisposable
```

**Parameters**

* `callback` `(cell: IDragCellPosition) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `onSelectionChange`

Callback for selection changes.

**Signature**

```typescript
onSelectionChange(callback: (selections: IRange[]) => void): IDisposable
```

**Parameters**

* `callback` `(selections: IRange[]) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

**Tags**

* `@callback` — onSelectionChangeCallback

Source: 

`@univerjs/sheets`

### `parseSheetHyperlink`

Parse the hyperlink string to get the hyperlink info.

**Signature**

```typescript
parseSheetHyperlink(hyperlink: string): ISheetHyperLinkInfo
```

**Parameters**

* `hyperlink` `string` — The hyperlink string to parse.

**Returns**

* `ISheetHyperLinkInfo` — The parsed hyperlink info, including type, name, URL, and search parameters.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const info = fWorkbook.parseSheetHyperlink('#gid=sheet1&range=A1');
console.log(info);
```

Source: 

`@univerjs/sheets-hyper-link`

### `getUrlOfDefineName`

Create a hyperlink url for the defined name. The defined name must exist in the current workbook and must be a reference to a range, otherwise an error will be thrown.

**Signature**

```typescript
getUrlOfDefineName(name: string): string
```

**Parameters**

* `name` `string` — The name of the defined name.

**Returns**

* `string` — The hyperlink url of the defined name.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();

// Create a defined name "TestRange" for the range A1:B10 of the active sheet
const definedNameParam = fWorkbook.newDefinedNameBuilder()
  .setName('TestRange')
  .setRef('Sheet1!$A$1:$B$10')
  .build();
fWorkbook.insertDefinedNameBuilder(definedNameParam);

// Create a hyperlink to the defined name "TestRange" on cell C1
const url = fWorkbook.getUrlOfDefineName('TestRange');
console.log(url);
const fRange = fWorksheet.getRange('C1');
fRange.setHyperLink(url, 'Link to TestRange');

// Create a hyperlink to the exiting defined name on cell C2
const definedNames = fWorkbook.getDefinedNames();
console.log(definedNames);
const exitsDefinedNameUrl = fWorkbook.getUrlOfDefineName(definedNames[0].getName());
console.log(exitsDefinedNameUrl);
const fRange2 = fWorksheet.getRange('C2');
fRange2.setHyperLink(exitsDefinedNameUrl, `Link to ${definedNames[0].getName()}`);
```

Source: 

`@univerjs/sheets-hyper-link`

### `redo`

Redo the last undone action.

**Signature**

```typescript
redo(): FWorkbook
```

**Returns**

* `FWorkbook` — A promise that resolves to true if the redo was successful, false otherwise.

**Examples**

```ts
// The code below redoes the last undone action
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.redo();
```

Source: 

`@univerjs/sheets`

### `removeStyles`

Remove styles from the workbook styles.

**Signature**

```typescript
removeStyles(styleKeys: string[]): void
```

**Parameters**

* `styleKeys` `string[]` — *No description*

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();

// Add styles to the workbook styles
const styles = {
  'custom-style-1': {
    bg: {
      rgb: 'rgb(255, 0, 0)',
    }
  },
  'custom-style-2': {
    fs: 20,
    n: {
      pattern: '@'
    }
  }
};
fWorkbook.addStyles(styles);

// Set values with the new styles
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValues([
  [{ v: 'Hello', s: 'custom-style-1' }, { v: 'Univer', s: 'custom-style-1' }],
  [{ v: 'To', s: 'custom-style-1' }, { v: '0001', s: 'custom-style-2' }],
]);

// Remove the style `custom-style-1` after 2 seconds
setTimeout(() => {
  fWorkbook.removeStyles(['custom-style-1']);
  fWorksheet.refreshCanvas();
}, 2000);
```

Source: 

`@univerjs/sheets`

### `save`

Save workbook snapshot data, including conditional formatting, data validation, and other plugin data.

**Signature**

```typescript
save(): IWorkbookData
```

**Returns**

* `IWorkbookData` — Workbook snapshot data

**Examples**

```ts
// The code below saves the workbook snapshot data
const fWorkbook = univerAPI.getActiveWorkbook();
const snapshot = fWorkbook.save();
console.log(snapshot);
```

Source: 

`@univerjs/sheets`

### `saveScreenshotToClipboard`

**Signature**

```typescript
async saveScreenshotToClipboard(): Promise<boolean>
```

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs-pro/sheets-print`

### `setActiveRange`

Sets the selection region for active sheet.

**Signature**

```typescript
setActiveRange(range: FRange): FWorkbook
```

**Parameters**

* `range` `FRange` — *No description*

**Returns**

* `FWorkbook` — FWorkbook instance

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const range = fWorkbook.getActiveSheet().getRange('A10:B10');
fWorkbook.setActiveRange(range);
```

Source: 

`@univerjs/sheets`

### `setActiveSheet`

Sets the given worksheet to be the active worksheet in the workbook.

**Signature**

```typescript
setActiveSheet(sheet: FWorksheet | string): FWorksheet
```

**Parameters**

* `sheet` `string | FWorksheet` — *No description*

**Returns**

* `FWorksheet` — The active worksheet

**Examples**

```ts
// The code below sets the given worksheet to be the active worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheets()[1];
fWorkbook.setActiveSheet(sheet);
```

Source: 

`@univerjs/sheets`

### `setCustomMetadata`

Set custom metadata of workbook

**Signature**

```typescript
setCustomMetadata(custom: CustomData | undefined): FWorkbook
```

**Parameters**

* `custom` `CustomData` — metadata

**Returns**

* `FWorkbook` — FWorkbook

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setCustomMetadata({ key: 'value' });
```

Source: 

`@univerjs/sheets`

### `setLocale`

> [!WARN]
> Deprecated — use 
> 
> `setSpreadsheetLocale`
> 
>  instead.

**Signature**

```typescript
setLocale(locale: LocaleType): void
```

**Parameters**

* `locale` `LocaleType` — *No description*

Source: 

`@univerjs/sheets`

### `setNumfmtLocal`

Set the locale for number format display. This affects how numbers, dates, and currencies are formatted in the workbook.

**Signature**

```typescript
setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook
```

**Parameters**

* `locale` `INumfmtLocaleTag` — The locale tag to use (e.g. `'en_US'`, `'zh_CN'`, `'de_DE'`).

**Returns**

* `FWorkbook` — The current workbook instance, for chaining.

**Examples**

```ts
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setNumfmtLocal('de_DE');
```

Source: 

`@univerjs/sheets-numfmt`

### `setPermissionDialogVisible`

**Signature**

```typescript
setPermissionDialogVisible(visible: boolean): void
```

**Parameters**

* `visible` `boolean` — *No description*

Source: 

`@univerjs/sheets-ui`

### `setSpreadsheetLocale`

Set the locale of the workbook.

**Signature**

```typescript
setSpreadsheetLocale(locale: LocaleType): FWorkbook
```

**Parameters**

* `locale` `LocaleType` — *No description*

**Returns**

* `FWorkbook` — This workbook, for chaining

**Examples**

```ts
// The code below sets the locale of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setSpreadsheetLocale(univerAPI.Enum.LocaleType.EN_US);
console.log(fWorkbook.getLocale());
```

Source: 

`@univerjs/sheets`

### `showSelection`

**Signature**

```typescript
showSelection(): FWorkbook
```

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `startEditing`

**Signature**

```typescript
startEditing(): boolean
```

**Returns**

* `boolean` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `transparentSelection`

**Signature**

```typescript
transparentSelection(): FWorkbook
```

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs/sheets-ui`

### `undo`

Undo the last action.

**Signature**

```typescript
undo(): FWorkbook
```

**Returns**

* `FWorkbook` — A promise that resolves to true if the undo was successful, false otherwise.

**Examples**

```ts
// The code below undoes the last action
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.undo();
```

Source: 

`@univerjs/sheets`

### Print

### `closePrintDialog`

**Signature**

```typescript
closePrintDialog(): void
```

Source: 

`@univerjs-pro/sheets-print`

### `openPrintDialog`

**Signature**

```typescript
openPrintDialog(): void
```

Source: 

`@univerjs-pro/sheets-print`

### `print`

**Signature**

```typescript
print(): void
```

Source: 

`@univerjs-pro/sheets-print`

### `updatePrintConfig`

**Signature**

```typescript
updatePrintConfig(config: ISheetPrintLayoutConfig): FWorkbook
```

**Parameters**

* `config` `ISheetPrintLayoutConfig` — *No description*

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs-pro/sheets-print`

### `updatePrintRenderConfig`

**Signature**

```typescript
updatePrintRenderConfig(config: ISheetPrintRenderConfig): FWorkbook
```

**Parameters**

* `config` `ISheetPrintRenderConfig` — *No description*

**Returns**

* `FWorkbook` — See signature above.

Source: 

`@univerjs-pro/sheets-print`

### Tables

### `addTable`

**Signature**

```typescript
async addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<string | undefined>
```

**Parameters**

* `subUnitId` `string` — *No description*
* `tableName` `string` — *No description*
* `rangeInfo` `ITableRange` — *No description*
* `tableId` `string` *(optional)* — *No description*
* `options` `ITableOptions` *(optional)* — *No description*

**Returns**

* `Promise<string>` — See signature above.

Source: 

`@univerjs/sheets-table`

### `getTableInfo`

**Signature**

```typescript
getTableInfo(tableId: string): ITableInfoWithUnitId | undefined
```

**Parameters**

* `tableId` `string` — *No description*

**Returns**

* `any` — See signature above.

Source: 

`@univerjs/sheets-table`

### `getTableList`

**Signature**

```typescript
getTableList(): ITableInfoWithUnitId[]
```

**Returns**

* `ITableInfoWithUnitId[]` — See signature above.

Source: 

`@univerjs/sheets-table`

### `removeTable`

**Signature**

```typescript
async removeTable(tableId: string): Promise<boolean>
```

**Parameters**

* `tableId` `string` — *No description*

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-table`

### `setEditable`

Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.

**Signature**

```typescript
setEditable(value: boolean): FWorkbook
```

**Parameters**

* `value` `boolean` — *No description*

**Returns**

* `FWorkbook` — FWorkbook instance

**Examples**

```ts
// The code below sets the editing permissions of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setEditable(false);
```

Source: 

`@univerjs/sheets`

### `setTableFilter`

**Signature**

```typescript
setTableFilter(tableId: string, column: number, filter: ITableFilterItem | undefined): Promise<boolean>
```

**Parameters**

* `tableId` `string` — *No description*
* `column` `number` — *No description*
* `filter` `any` — *No description*

**Returns**

* `Promise<boolean>` — See signature above.

Source: 

`@univerjs/sheets-table`
