API Reference

FWorkbook

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

Get this object from the initialized univerAPI instance. The example assumes a workbook is already open.

TypeScript
const workbook = univerAPI.getActiveWorkbook()if (!workbook) throw new Error('No active workbook')console.log(workbook.getSheets().map((sheet) => sheet.getName()))

Access

Access through:

Setup

Register @univerjs/sheets or a preset that includes it. In plugin mode, import @univerjs/sheets/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs/sheets

FWorkbook.addStyles

Add styles to the workbook styles.

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

Parameters

  • styles — Required. Styles to add

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Add styles to the workbook stylesconst 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 stylesconst fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')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' },  ],])

Types: Record · IStyleData

Package: @univerjs/sheets · Type definitions

FWorkbook.create

Create a new worksheet and returns a handle to it.

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

Parameters

  • name — Required. Name of the new sheet
  • rows — Required. How many rows would the new sheet have
  • columns — Required. How many columns would the new sheet have
  • options — Optional. The options for the new sheet

Returns

The new created sheet

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Create a new sheet named 'MyNewSheet' with 10 rows and 10 columnsconst 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 sheetconst 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)

Types: FWorksheet · Partial · IWorksheetData

Package: @univerjs/sheets · Type definitions

FWorkbook.createRangeThemeStyle

Create a range theme style.

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

Parameters

  • themeName — Required. The name of the theme to register
  • themeStyleJson — Optional. The theme style json to register

Returns

  • The created range theme style

Examples

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

Types: RangeThemeStyle · Omit · IRangeThemeStyleJSON

Package: @univerjs/sheets · Type definitions

FWorkbook.deleteActiveSheet

Deletes the currently active sheet.

TypeScript
deleteActiveSheet(): boolean

Returns

true if the sheet was deleted, false otherwise

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.deleteActiveSheet()

Package: @univerjs/sheets · Type definitions

FWorkbook.deleteDefinedName

Delete the defined name with the given name.

TypeScript
deleteDefinedName(name: string): boolean

Parameters

  • name — Required. The name of the defined name to delete

Returns

true if the defined name was deleted, false otherwise

Examples

TypeScript
// The code below deletes the defined name with the given nameconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.deleteDefinedName('MyDefinedName')

Package: @univerjs/sheets · Type definitions

FWorkbook.deleteSheet

Deletes the specified worksheet.

TypeScript
deleteSheet(sheet: FWorksheet | string): boolean

Parameters

  • sheet — Required. The instance or id of the worksheet to delete.

Returns

True if the worksheet was deleted, false otherwise.

Examples

TypeScript
// The code below deletes the specified worksheetconst fWorkbook = univerAPI.getActiveWorkbook()const sheet = fWorkbook.getSheets()[1]fWorkbook.deleteSheet(sheet)// The code below deletes the specified worksheet by id// fWorkbook.deleteSheet(sheet.getSheetId());

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.dispose

Releases this facade's resources. Use univerAPI.disposeUnit() to unload the owning unit.

TypeScript
dispose(): void

Package: @univerjs/sheets · Type definitions

FWorkbook.duplicateActiveSheet

Duplicates the active sheet.

TypeScript
duplicateActiveSheet(): FWorksheet

Returns

The duplicated worksheet

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const duplicatedSheet = fWorkbook.duplicateActiveSheet()console.log(duplicatedSheet)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.duplicateSheet

Duplicates the given worksheet.

TypeScript
duplicateSheet(sheet: FWorksheet): FWorksheet

Parameters

  • sheet — Required. The worksheet to duplicate.

Returns

The duplicated worksheet

Examples

TypeScript
// The code below duplicates the given worksheetconst fWorkbook = univerAPI.getActiveWorkbook()const activeSheet = fWorkbook.getSheetByName('Sheet1')if (!activeSheet) throw new Error('activeSheet is not available')const duplicatedSheet = fWorkbook.duplicateSheet(activeSheet)console.log(duplicatedSheet)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.getActiveCell

Returns the active cell in this spreadsheet.

TypeScript
getActiveCell(): FRange | null

Returns

The active cell

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()console.log(fWorkbook.getActiveCell().getA1Notation())

Types: FRange

Package: @univerjs/sheets · Type definitions

FWorkbook.getActiveRange

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

TypeScript
getActiveRange(): FRange | null

Returns

The active range

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const activeRange = fWorkbook.getActiveRange()console.log(activeRange)

Types: FRange

Package: @univerjs/sheets · Type definitions

FWorkbook.getActiveSheet

Get the active sheet of the workbook.

TypeScript
getActiveSheet(): FWorksheet

Returns

The active sheet of the workbook

Examples

TypeScript
// The code below gets the active sheet of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()if (!fWorksheet) throw new Error('fWorksheet is not available')console.log(fWorksheet)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.getCustomMetadata

Get custom metadata of workbook

TypeScript
getCustomMetadata(): CustomData | undefined

Returns

custom metadata

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const custom = fWorkbook.getCustomMetadata()console.log(custom)

Types: CustomData

Package: @univerjs/sheets · Type definitions

FWorkbook.getDefinedName

Get the defined name by name.

TypeScript
getDefinedName(name: string): FDefinedName | null

Parameters

  • name — Required. The name of the defined name to get

Returns

The defined name with the given name

Examples

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

Types: FDefinedName

Package: @univerjs/sheets · Type definitions

FWorkbook.getDefinedNames

Get all the defined names in the workbook.

TypeScript
getDefinedNames(): FDefinedName[]

Returns

All the defined names in the workbook

Examples

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

Types: FDefinedName

Package: @univerjs/sheets · Type definitions

FWorkbook.getId

Get the id of the workbook.

TypeScript
getId(): string

Returns

The id of the workbook.

Examples

TypeScript
// The code below gets the id of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()const unitId = fWorkbook.getId()console.log(unitId)

Package: @univerjs/sheets · Type definitions

FWorkbook.getName

Get the name of the workbook.

TypeScript
getName(): string

Returns

The name of the workbook.

Examples

TypeScript
// The code below gets the name of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()const name = fWorkbook.getName()console.log(name)

Package: @univerjs/sheets · Type definitions

FWorkbook.getNumSheets

Get the number of sheets in the workbook.

TypeScript
getNumSheets(): number

Returns

The number of sheets in the workbook

Examples

TypeScript
// The code below gets the number of sheets in the workbookconst fWorkbook = univerAPI.getActiveWorkbook()console.log(fWorkbook.getNumSheets())

Package: @univerjs/sheets · Type definitions

FWorkbook.getRegisteredRangeThemes

Gets the registered range themes.

TypeScript
getRegisteredRangeThemes(): string[]

Returns

The name list of registered range themes.

Examples

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

Package: @univerjs/sheets · Type definitions

FWorkbook.getSheetByName

Get a worksheet by sheet name.

TypeScript
getSheetByName(name: string): FWorksheet | null

Parameters

  • name — Required. The name of the sheet to get.

Returns

The worksheet with given sheet name

Examples

TypeScript
// The code below gets a worksheet by sheet nameconst fWorkbook = univerAPI.getActiveWorkbook()const sheet = fWorkbook.getSheetByName('Sheet1')console.log(sheet)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.getSheetBySheetId

Get a worksheet by sheet id.

TypeScript
getSheetBySheetId(sheetId: string): FWorksheet | null

Parameters

  • sheetId — Required. The id of the sheet to get.

Returns

The worksheet with given sheet id

Examples

TypeScript
// The code below gets a worksheet by sheet idconst fWorkbook = univerAPI.getActiveWorkbook()const sheet = fWorkbook.getSheetBySheetId('sheetId')console.log(sheet)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.getSheets

Gets all the worksheets in this workbook

TypeScript
getSheets(): FWorksheet[]

Returns

An array of all the worksheets in the workbook

Examples

TypeScript
// The code below gets all the worksheets in the workbookconst fWorkbook = univerAPI.getActiveWorkbook()const sheets = fWorkbook.getSheets()console.log(sheets)

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.getUrl

Get the URL of the workbook.

TypeScript
getUrl(): string

Returns

The URL of the workbook

Examples

TypeScript
// The code below gets the URL of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()const url = fWorkbook.getUrl()console.log(url)

Package: @univerjs/sheets · Type definitions

FWorkbook.getWorkbook

Get the Workbook instance.

TypeScript
getWorkbook(): Workbook

Returns

The Workbook instance.

Examples

TypeScript
// The code below gets the Workbook instanceconst fWorkbook = univerAPI.getActiveWorkbook()const workbook = fWorkbook.getWorkbook()console.log(workbook)

Types: Workbook

Package: @univerjs/sheets · Type definitions

FWorkbook.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.

TypeScript
getWorkbookPermission(): FWorkbookPermission

Returns

  • The WorkbookPermission instance.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()// Set workbook to read-only modeawait permission.setMode('viewer')// Add a collaboratorawait permission.addCollaborator({  userId: 'user123',  name: 'John Doe',  role: 'editor',})// Subscribe to permission changespermission.permission$.subscribe((snapshot) => {  console.log('Permissions changed:', snapshot)})

Types: FWorkbookPermission

Package: @univerjs/sheets · Type definitions

FWorkbook.id

The workbook unit id used to identify this workbook in commands and snapshots.

TypeScript
readonly id: string

Package: @univerjs/sheets · Type definitions

FWorkbook.insertDefinedName

Insert a defined name.

TypeScript
insertDefinedName(name: string, formulaOrRefString: string): FWorkbook

Parameters

  • name — Required. The name of the defined name to insert
  • formulaOrRefString — Required. The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert

Returns

The current FWorkbook instance

Examples

TypeScript
// The code below inserts a defined nameconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.insertDefinedName('MyDefinedName', 'Sheet1!$A$1')

Types: FWorkbook

Package: @univerjs/sheets · Type definitions

FWorkbook.insertDefinedNameBuilder

Insert a defined name by builder param.

TypeScript
insertDefinedNameBuilder(param: ISetDefinedNameMutationParam): void

Parameters

  • param — Required. The param to insert the defined name

Examples

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

Types: ISetDefinedNameMutationParam

Package: @univerjs/sheets · Type definitions

FWorkbook.insertSheet

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

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

Parameters

  • sheetName — Optional. The name of the new sheet
  • options — Optional. The options for the new sheet

Returns

The new sheet

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Create a new sheet with default configurationconst newSheet = fWorkbook.insertSheet()console.log(newSheet)// Create a new sheet with custom name and default configurationconst newSheetWithName = fWorkbook.insertSheet('MyNewSheet')console.log(newSheetWithName)// Create a new sheet with custom name and custom configurationconst 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)

Types: FWorksheet · Partial · IWorksheetData

Package: @univerjs/sheets · Type definitions

FWorkbook.moveActiveSheet

Move the active sheet to the specified index.

TypeScript
moveActiveSheet(index: number): FWorkbook

Parameters

  • index — Required. The index to move the active sheet to

Returns

This workbook, for chaining

Examples

TypeScript
// The code below moves the active sheet to the specified indexconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.moveActiveSheet(1)

Types: FWorkbook

Package: @univerjs/sheets · Type definitions

FWorkbook.moveSheet

Move the sheet to the specified index.

TypeScript
moveSheet(sheet: FWorksheet, index: number): FWorkbook

Parameters

  • sheet — Required. The sheet to move
  • index — Required. The index to move the sheet to

Returns

This workbook, for chaining

Examples

TypeScript
// The code below moves the sheet to the specified indexconst fWorkbook = univerAPI.getActiveWorkbook()const sheet = fWorkbook.getSheetByName('Sheet1')if (!sheet) throw new Error('sheet is not available')fWorkbook.moveSheet(sheet, 1)

Types: FWorkbook · FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.newDefinedNameBuilder

Create a new defined name builder.

TypeScript
newDefinedNameBuilder(): FDefinedNameBuilder

Returns

  • The defined name builder.

Examples

TypeScript
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)

Types: FDefinedNameBuilder

Package: @univerjs/sheets · Type definitions

FWorkbook.onBeforeCommandExecute

Callback for command execution.

Register a callback that will be triggered before invoking a command targeting the Univer sheet.

TypeScript
onBeforeCommandExecute(callback: CommandListener): IDisposable

Parameters

  • callback — Required. the callback.

Returns

A function to dispose the listening.

Examples

TypeScript
// The code below registers a callback that will be triggered before invoking a command targeting the Univer sheetconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.onBeforeCommandExecute((command) => {  console.log('Before command execute:', command)})

Types: IDisposable · CommandListener

Package: @univerjs/sheets · Type definitions

FWorkbook.onCommandExecuted

Callback for command execution.

Register a callback that will be triggered when a command is invoked targeting the Univer sheet.

TypeScript
onCommandExecuted(callback: CommandListener): IDisposable

Parameters

  • callback — Required. the callback.

Returns

A function to dispose the listening.

Examples

TypeScript
// The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheetconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.onCommandExecuted((command) => {  console.log('Command executed:', command)})

Types: IDisposable · CommandListener

Package: @univerjs/sheets · Type definitions

FWorkbook.onSelectionChange

Callback for selection changes.

Register a callback that will be triggered when the selection changes.

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

Parameters

  • callback — Required. The callback.

Returns

A function to dispose the listening

Examples

TypeScript
// The code below registers a callback that will be triggered when the selection changesconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.onSelectionChange((selections) => {  console.log('Selection changed:', selections)})

Types: IDisposable · IRange

Package: @univerjs/sheets · Type definitions

FWorkbook.redo

Redo the last undone action.

TypeScript
redo(): FWorkbook

Returns

This workbook, for chaining.

Examples

TypeScript
// The code below redoes the last undone actionconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.redo()

Types: FWorkbook

Package: @univerjs/sheets · Type definitions

FWorkbook.registerRangeTheme

Register a custom range theme style.

TypeScript
registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void

Parameters

  • rangeThemeStyle — Required. The range theme style to register

Examples

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

Types: RangeThemeStyle

Package: @univerjs/sheets · Type definitions

FWorkbook.removeStyles

Remove styles from the workbook styles.

TypeScript
removeStyles(styleKeys: string[]): void

Parameters

  • styleKeys — Required. Style keys to remove

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Add styles to the workbook stylesconst 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 stylesconst fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')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 secondssetTimeout(() => {  fWorkbook.removeStyles(['custom-style-1'])  fWorksheet.refreshCanvas()}, 2000)

Package: @univerjs/sheets · Type definitions

FWorkbook.save

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

TypeScript
save(): IWorkbookData

Returns

Workbook snapshot data

Examples

TypeScript
// The code below saves the workbook snapshot dataconst fWorkbook = univerAPI.getActiveWorkbook()const snapshot = fWorkbook.save()console.log(snapshot)

Types: IWorkbookData

Package: @univerjs/sheets · Type definitions

FWorkbook.setActiveRange

Sets the selection region for active sheet.

TypeScript
setActiveRange(range: FRange): FWorkbook

Parameters

  • range — Required. The range to set as the active selection.

Returns

FWorkbook instance

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const range = fWorksheet.getRange('A10:B10')fWorkbook.setActiveRange(range)

Types: FWorkbook · FRange

Package: @univerjs/sheets · Type definitions

FWorkbook.setActiveSheet

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

TypeScript
setActiveSheet(sheet: FWorksheet | string): FWorksheet

Parameters

  • sheet — Required. The instance or id of the worksheet to set as active.

Returns

The active worksheet

Examples

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

Types: FWorksheet

Package: @univerjs/sheets · Type definitions

FWorkbook.setCustomMetadata

Set custom metadata of workbook

TypeScript
setCustomMetadata(custom: CustomData | undefined): FWorkbook

Parameters

  • custom — Required. custom metadata

Returns

FWorkbook

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.setCustomMetadata({ key: 'value' })

Types: FWorkbook · CustomData

Package: @univerjs/sheets · Type definitions

FWorkbook.setEditable

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

TypeScript
setEditable(value: boolean): FWorkbook

Parameters

  • value — Required. editable value want to set

Returns

FWorkbook instance

Examples

TypeScript
// The code below sets the editing permissions of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.setEditable(false)

Types: FWorkbook

Package: @univerjs/sheets · Type definitions

FWorkbook.setName

Set the name of the workbook.

TypeScript
setName(name: string): this

Parameters

  • name — Required. The new name of the workbook.

Returns

The current FWorkbook instance for chaining.

Examples

TypeScript
// The code below sets the name of the workbookconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.setName('MyWorkbook')

Package: @univerjs/sheets · Type definitions

FWorkbook.undo

Undo the last action.

TypeScript
undo(): FWorkbook

Returns

This workbook, for chaining.

Examples

TypeScript
// The code below undoes the last actionconst fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.undo()

Types: FWorkbook

Package: @univerjs/sheets · Type definitions

FWorkbook.unregisterRangeTheme

Unregister a custom range theme style.

TypeScript
unregisterRangeTheme(themeName: string): void

Parameters

  • themeName — Required. The name of the theme to unregister

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.unregisterRangeTheme('MyTheme')

Package: @univerjs/sheets · Type definitions

FWorkbook.updateDefinedNameBuilder

Update the defined name with the given name.

TypeScript
updateDefinedNameBuilder(param: ISetDefinedNameMutationParam): void

Parameters

  • param — Required. The param to insert the defined name

Examples

TypeScript
// The code below updates the defined name with the given nameconst fWorkbook = univerAPI.getActiveWorkbook()const definedName = fWorkbook.getDefinedName('MyDefinedName')console.log(definedName?.getFormulaOrRefString())// Update the defined nameif (definedName) {  const newDefinedNameParam = definedName    .toBuilder()    .setName('NewDefinedName')    .setRef('Sheet1!$A$2')    .build()  fWorkbook.updateDefinedNameBuilder(newDefinedNameParam)}

Types: ISetDefinedNameMutationParam

Package: @univerjs/sheets · Type definitions

@univerjs/sheets-data-validation

FWorkbook.getAllDataValidationErrorAsync

Get all data validation errors for current workbook.

TypeScript
getAllDataValidationErrorAsync(): Promise<IDataValidationError[]>

Returns

A promise that resolves to an array of validation errors.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const errors = await fWorkbook.getAllDataValidationErrorAsync()console.log(errors)

Types: IDataValidationError · Promise

Package: @univerjs/sheets-data-validation · Type definitions

FWorkbook.getValidatorStatus

Get data validation validator status for current workbook.

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

Returns

A promise resolving to an object keyed by sheet ID, with a validation-status matrix for each sheet.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const status = await fWorkbook.getValidatorStatus()console.log(status)

Types: Record · ObjectMatrix · Nullable · DataValidationStatus · Promise

Package: @univerjs/sheets-data-validation · Type definitions

@univerjs/sheets-formula

FWorkbook.getAllFormulaError

Get all formula errors in the workbook

TypeScript
getAllFormulaError(): ISheetFormulaError[]

Returns

Array of formula errors

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const errors = fWorkbook.getAllFormulaError()console.log('Formula errors:', errors)

Types: ISheetFormulaError

Package: @univerjs/sheets-formula · Type definitions

FWorkbook.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.

TypeScript
getUrlOfDefineName(name: string): string

Parameters

  • name — Required. The name of the defined name.

Returns

The hyperlink url of the defined name.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a defined name "TestRange" for the range A1:B10 of the active sheetconst 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 C1const 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 C2const 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()}`)

Package: @univerjs/sheets-hyper-link · Type definitions

Parse the hyperlink string to get the hyperlink info.

TypeScript
parseSheetHyperlink(hyperlink: string): ISheetHyperLinkInfo

Parameters

  • hyperlink — Required. The hyperlink string.

Returns

The hyperlink info.

Examples

TypeScript
// Create a hyperlink to the range A1:D10 of the current sheetconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:D10')const hyperlink = fRange.getUrl()// Parse the hyperlinkconst hyperlinkInfo = fWorkbook.parseSheetHyperlink(hyperlink)console.log(hyperlinkInfo)

Types: ISheetHyperLinkInfo

Package: @univerjs/sheets-hyper-link · Type definitions

Navigate to the sheet hyperlink.

TypeScript
navigateToSheetHyperlink(hyperlink: string): void

Parameters

  • hyperlink — Required. The hyperlink string

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const sheets = fWorkbook.getSheets()// Create a hyperlink to the cell F6 in the first sheetconst sheet1 = sheets[0]const range = sheet1.getRange('F6')const hyperlink = range.getUrl()// Switch to the second sheetfWorkbook.setActiveSheet(sheets[1])console.log(fWorkbook.getActiveSheet().getSheetName())// Navigate to the hyperlink after 3 secondssetTimeout(() => {  fWorkbook.navigateToSheetHyperlink(hyperlink)  console.log(fWorkbook.getActiveSheet().getSheetName())}, 3000)

Types: FWorkbook

Package: @univerjs/sheets-hyper-link-ui · Type definitions

@univerjs/sheets-numfmt

FWorkbook.setNumfmtLocal

Set the locale for number formatting.

TypeScript
setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook

Parameters

  • locale — Required. zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi

Returns

The FWorkbook instance for chaining.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1')fRange.setValue(1234.567).setNumberFormat('#,##0.00')// Set the locale en_US for number formatting.fWorkbook.setNumfmtLocal('en_US')console.log(fRange.getDisplayValue()) // 1,234.57// Set the locale de_DE for number formatting.fWorkbook.setNumfmtLocal('de_DE')console.log(fRange.getDisplayValue()) // 1.234,57

Types: FWorkbook · INumfmtLocaleTag

Package: @univerjs/sheets-numfmt · Type definitions

@univerjs/sheets-table

FWorkbook.addTable

Add table

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

Parameters

  • subUnitId — Required. The sub unit id
  • tableName — Required. The table name
  • rangeInfo — Required. The table range information
  • tableId — Optional. The table id
  • options — Optional. The table options

Returns

A promise resolving to the table ID, or undefined if the name is invalid or creation fails.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const id = await fWorkbook.addTable(fWorksheet.getSheetId(), 'name-1', fRange.getRange(), 'id-1', {  tableStyleId: 'table-default-4',})if (id) {  const tableInfo = fWorkbook.getTableInfo(id)  console.log('debugger tableInfo', tableInfo)}

Types: Promise · ITableRange · ITableOptions

Package: @univerjs/sheets-table · Type definitions

FWorkbook.getTableInfo

Get table information

TypeScript
getTableInfo(tableId: string): ITableInfoWithUnitId | undefined

Parameters

  • tableId — Required. The table id

Returns

The table information, including workbook and worksheet IDs, or undefined if not found.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable('name-1', fRange.getRange(), 'id-1', {  tableStyleId: 'table-default-4',})if (success) {  const tableInfo = fWorkbook.getTableInfo('id-1')  console.log('debugger tableInfo', tableInfo)}

Types: ITableInfoWithUnitId

Package: @univerjs/sheets-table · Type definitions

FWorkbook.getTableInfoByName

Get table information by name

TypeScript
getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined

Parameters

  • tableName — Required. The table name

Returns

The table information, including workbook and worksheet IDs, or undefined if not found.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable('name-1', fRange.getRange(), 'id-1', {  tableStyleId: 'table-default-4',})if (success) {  const tableInfo = fWorkbook.getTableInfoByName('name-1')  console.log('debugger tableInfo', tableInfo)}

Types: ITableInfoWithUnitId

Package: @univerjs/sheets-table · Type definitions

FWorkbook.getTableList

Get table list

TypeScript
getTableList(): ITableInfoWithUnitId[]

Returns

The table list

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const tables = fWorkbook.getTableList()console.log('debugger tables', tables)

Types: ITableInfoWithUnitId

Package: @univerjs/sheets-table · Type definitions

FWorkbook.removeTable

Remove table

TypeScript
removeTable(tableId: string): Promise<boolean>

Parameters

  • tableId — Required. The table id

Returns

A promise resolving to whether the table was removed; false if the table is not found.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const tableInfo = fWorkbook.getTableInfo('id-1')console.log('debugger tableInfo', tableInfo)if (tableInfo) {  // Remove the table with the specified id  await fWorkbook.removeTable('id-1')}

Types: Promise

Package: @univerjs/sheets-table · Type definitions

FWorkbook.setTableFilter

set table filter

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

Parameters

  • tableId — Required. The table id
  • column — Required. The column index, starting from 0.
  • filter — Required. The filter to apply, or undefined to clear the column filter.

Returns

The result of set table filter

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a table in the range B2:F11const fRange = fWorksheet.getRange('B2:F11')const success = await fWorksheet.addTable('name-1', fRange.getRange(), 'id-1', {  tableStyleId: 'table-default-4',})if (success) {  // Set the filter for the second column  await fWorkbook.setTableFilter('id-1', 1, {    filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition,    filterInfo: {      conditionType: univerAPI.Enum.TableConditionTypeEnum.Number,      compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan,      expectedValue: 10,    },  })  const tableInfo = fWorkbook.getTableInfo('id-1')  console.log('debugger tableInfo', tableInfo)}

Types: Promise · ITableFilterItem

Package: @univerjs/sheets-table · Type definitions

@univerjs/sheets-thread-comment

FWorkbook.clearComments

Clear all comments in the current workbook

TypeScript
clearComments(): Promise<boolean>

Returns

Whether the comments are cleared successfully.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const result = await fWorkbook.clearComments()console.log(result)

Types: Promise

Package: @univerjs/sheets-thread-comment · Type definitions

FWorkbook.getComments

Get all comments in the current workbook

TypeScript
getComments(): FThreadComment[]

Returns

All comments in the current workbook

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const comments = fWorkbook.getComments()comments.forEach((comment) => {  const isRoot = comment.getIsRoot()  if (isRoot) {    console.log('root comment:', comment.getCommentData())    const replies = comment.getReplies()    replies.forEach((reply) => {      console.log('reply comment:', reply.getCommentData())    })  }})

Types: FThreadComment

Package: @univerjs/sheets-thread-comment · Type definitions

@univerjs/sheets-ui

FWorkbook.abortEditingAsync

End the editing process of the current active cell, and discard the changes.

TypeScript
abortEditingAsync(): Promise<boolean>

Returns

Whether the editing process is ended successfully

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()await fWorkbook.abortEditingAsync()

Types: Promise

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.customizeColumnHeader

Customize the column header of the all worksheets in the workbook.

TypeScript
customizeColumnHeader(cfg: IColumnsHeaderCfgParam): void

Parameters

  • cfg — Required. The configuration of the column header.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.customizeColumnHeader({  headerStyle: {    fontColor: '#fff',    backgroundColor: '#4e69ee',    fontSize: 9,  },  columnsCfg: {    0: 'kuma II',    3: {      text: 'Size',      textAlign: 'left', // CanvasTextAlign      fontColor: '#fff',      fontSize: 12,      borderColor: 'pink',      backgroundColor: 'pink',    },    4: 'Wow',  },})

Types: IColumnsHeaderCfgParam

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.customizeRowHeader

Customize the row header of the all worksheets in the workbook.

TypeScript
customizeRowHeader(cfg: IRowsHeaderCfgParam): void

Parameters

  • cfg — Required. The configuration of the row header.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.customizeRowHeader({  headerStyle: {    backgroundColor: 'pink',    fontSize: 12,  },  rowsCfg: {    0: 'Moka II',    3: {      text: 'Size',      textAlign: 'left', // CanvasTextAlign    },  },})

Types: IRowsHeaderCfgParam

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.disableSelection

Disable selection. After disabled, there would be no response for selection.

TypeScript
disableSelection(): FWorkbook

Returns

FWorkbook instance for chaining

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.disableSelection()

Types: FWorkbook

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.enableSelection

Enable selection. After this you can select range.

TypeScript
enableSelection(): FWorkbook

Returns

FWorkbook instance for chaining

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.enableSelection()

Types: FWorkbook

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.endEditingAsync

End the editing process of the current active cell

TypeScript
endEditingAsync(save?: boolean): Promise<boolean>

Parameters

  • save — Optional. Default: true. Whether to save the changes, default is true

Returns

Whether the editing process is ended successfully

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()await fWorkbook.endEditingAsync(false)

Types: Promise

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.getScrollStateBySheetId

Get scroll state of specified sheet.

TypeScript
getScrollStateBySheetId(sheetId: string): Nullable<IScrollState>

Parameters

  • sheetId — Required. sheet id

Returns

The sheet scroll state, or a nullish value when no state is available.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// scroll to cell D10fWorksheet.scrollToCell(9, 3)// get scroll stateconst scrollState = fWorkbook.getScrollStateBySheetId(fWorksheet.getSheetId())const { offsetX, offsetY, sheetViewStartRow, sheetViewStartColumn } = scrollStateconsole.log(scrollState) // sheetViewStartRow: 9, sheetViewStartColumn: 3, offsetX: 0, offsetY: 0

Types: IScrollState · Nullable

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.isCellEditing

Check if the current active cell is in editing state

TypeScript
isCellEditing(): boolean

Returns

True if the current active cell is in editing state, false otherwise

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const isEditing = fWorkbook.isCellEditing()console.log(isEditing)

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.showSelection

Set selection visible.

TypeScript
showSelection(): FWorkbook

Returns

FWorkbook instance for chaining

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.showSelection()

Types: FWorkbook

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.startEditing

Start the editing process of the current active cell

TypeScript
startEditing(): boolean

Returns

Whether the editing process is started successfully

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.startEditing()

Package: @univerjs/sheets-ui · Type definitions

FWorkbook.transparentSelection

Set selection invisible, Unlike disableSelection, selection still works, you just can not see them.

TypeScript
transparentSelection(): FWorkbook

Returns

FWorkbook instance for chaining

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.transparentSelection()

Types: FWorkbook

Package: @univerjs/sheets-ui · Type definitions

@univerjs-pro/range-preprocess

FWorkbook.getPreprocessRanges

Get all preprocess range information

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

Parameters

  • responseDataMode — Optional. The response data mode.

Returns

All preprocess range information

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const allTableInfo = fWorkbook.getPreprocessRanges()console.log('debugger allTableInfo', allTableInfo)

Types: ITableJson · Record

Package: @univerjs-pro/range-preprocess · Type definitions

@univerjs-pro/sheets-pivot

FWorkbook.addPivotTable

Add a pivot table to the Workbook.

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

Parameters

  • sourceInfo — Required. The source data range info of the pivot table.
  • positionType — Required. whether new a sheet or insert a pivot table to the existing sheet.
  • anchorCellInfo — Required. The target cell info of the pivot table.

Returns

A promise that resolves to the added pivot table instance.

Examples

TypeScript
// should ensure the sheet range A1:G9 is not emptyconst fWorkbook = univerAPI.getActiveWorkbook()const unitId = fWorkbook.getId()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const subUnitId = fWorksheet.getSheetId()const sheetName = fWorksheet.getSheetName()const sourceInfo = {  unitId,  subUnitId,  sheetName,  range: {    startRow: 0,    endRow: 8,    startColumn: 0,    endColumn: 6,  },}const anchorCellInfo = {  unitId,  subUnitId,  row: 0,  col: 8,}const fPivotTable = await fWorkbook.addPivotTable(  sourceInfo,  univerAPI.Enum.PositionTypeEnum.Existing,  anchorCellInfo,)await fPivotTable?.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)await fPivotTable?.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Value, 0)

Types: FPivotTable · Promise · IUnitRangeName · PositionType · IPivotCellPositionInfo

Package: @univerjs-pro/sheets-pivot · Type definitions

FWorkbook.getPivotTableByCell

Get the pivot table id by the cell.

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

Parameters

  • unitId — Required. The unit id of workbook.
  • subUnitId — Required. The sheet id, which pivot table belongs to.
  • row — Required. The checked row.
  • col — Required. The checked column.

Returns

The pivot table instance or undefined.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const unitId = fWorkbook.getId()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const subUnitId = fWorksheet.getSheetId()const fPivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 0, 8)if (fPivotTable) {  fPivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)}

Types: FPivotTable

Package: @univerjs-pro/sheets-pivot · Type definitions

FWorkbook.getPivotTableById

Get the pivot table by the pivot table id.

TypeScript
getPivotTableById(pivotTableId: string): FPivotTable | undefined

Parameters

  • pivotTableId — Required. The pivot table id.

Returns

The pivot table instance or undefined.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const mockId = 'abc123456'const fPivotTable = fWorkbook.getPivotTableById(mockId)if (fPivotTable) {  fPivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)}

Types: FPivotTable

Package: @univerjs-pro/sheets-pivot · Type definitions

@univerjs-pro/sheets-pivot-chart

FWorkbook.getPivotChartById

Returns a PivotChart in this workbook by its stable identifier.

TypeScript
getPivotChartById(pivotChartId: string): FSheetPivotChart | null

Parameters

  • pivotChartId — Required. The identifier returned by FSheetPivotChart.getId().

Returns

A live facade, or null if it is absent from this workbook.

Examples

TypeScript
import '@univerjs-pro/sheets-pivot-chart/facade'const fWorkbook = univerAPI.getActiveWorkbook()const fPivotChart = fWorkbook.getPivotChartById('pivot-chart-1')console.log(fPivotChart?.getInfo())

Types: FSheetPivotChart

Package: @univerjs-pro/sheets-pivot-chart · Type definitions

@univerjs-pro/sheets-print

FWorkbook.closePrintDialog

Close print preview dialog.

TypeScript
closePrintDialog(): void

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.openPrintDialog()// Close print dialog after 3 secondssetTimeout(() => {  fWorkbook.closePrintDialog()}, 3000)

Package: @univerjs-pro/sheets-print · Type definitions

FWorkbook.openPrintDialog

Open print preview dialog.

TypeScript
openPrintDialog(): void

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.openPrintDialog()

Package: @univerjs-pro/sheets-print · Type definitions

FWorkbook.print

Using current print config and render config to print.

TypeScript
print(): void

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Update print layout config by defaultfWorkbook.updatePrintConfig({})// Update print render config by defaultfWorkbook.updatePrintRenderConfig({})// Start printfWorkbook.print()

Package: @univerjs-pro/sheets-print · Type definitions

FWorkbook.saveScreenshotToClipboard

Save screenshot of current range to clipboard. This API is only available with a license. Without a license, usage is restricted, and save operations will return false. We use the Clipboard API to save the image to the clipboard, which may fail in an insecure network environment or in some unsupported browsers. A successful save will return true.

TypeScript
saveScreenshotToClipboard(): Promise<boolean>

Returns

  • The result of saving the screenshot to the clipboard.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const result = await fWorkbook.saveScreenshotToClipboard()console.log(result) // true or false

Types: Promise

Package: @univerjs-pro/sheets-print · Type definitions

FWorkbook.updatePrintConfig

Update print config, include print area, page-setting, scale, freeze, margin, and etc.

TypeScript
updatePrintConfig(config: ISheetPrintLayoutConfig): FWorkbook

Parameters

  • config — Required. The print layout config.

Returns

  • The current workbook instance for chaining.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const subUnitId = fWorksheet.getSheetId()// Update print layout configfWorkbook.updatePrintConfig({  area: univerAPI.Enum.PrintArea.CurrentSheet, // print current sheet  subUnitIds: [subUnitId],  paperSize: univerAPI.Enum.PrintPaperSize.A4, // A4 paper size  scale: univerAPI.Enum.PrintScale.FitPage, // fit content to page  freeze: [univerAPI.Enum.PrintFreeze.Row], // freeze row headers  margin: univerAPI.Enum.PrintPaperMargin.Normal, // normal margin  // ... other settings})// Start printfWorkbook.print()

Types: FWorkbook · ISheetPrintLayoutConfig

Package: @univerjs-pro/sheets-print · Type definitions

FWorkbook.updatePrintRenderConfig

Update print render config, include print header-footer setting, alignment, gridline, and etc.

TypeScript
updatePrintRenderConfig(config: ISheetPrintRenderConfig): FWorkbook

Parameters

  • config — Required. The print render config.

Returns

  • The current workbook instance for chaining.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Update print layout config by defaultfWorkbook.updatePrintConfig({})// Update print render configfWorkbook.updatePrintRenderConfig({  gridlines: true, // show gridlines  hAlign: univerAPI.Enum.PrintAlign.Middle, // horizontal align middle  vAlign: univerAPI.Enum.PrintAlign.Middle, // vertical align middle  headerFooter: [    // the array of header and footer elements to include, here is page numbers and worksheet name    univerAPI.Enum.PrintHeaderFooter.PageSize,    univerAPI.Enum.PrintHeaderFooter.WorksheetTitle,  ],  // ... other settings})// Start printfWorkbook.print()

Types: FWorkbook · ISheetPrintRenderConfig

Package: @univerjs-pro/sheets-print · Type definitions

How is this guide?

© 2026 DreamNum Co., Ltd.