Workbook

GitHubEdit on GitHub
Packages@univerjs/sheets-ui, @univerjs-pro/sheets-pivot, @univerjs/sheets, @univerjs/sheets-table, @univerjs/sheets-thread-comment, @univerjs-pro/sheets-print, @univerjs/sheets-zen-editor, @univerjs-labs/local-snapshot-manager, @univerjs/sheets-data-validation, @univerjs/sheets-formula, @univerjs-labs/sheets-mcp, @univerjs-pro/range-preprocess, @univerjs/sheets-hyper-link-ui, @univerjs/sheets-hyper-link, @univerjs/sheets-numfmt
CORE

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

MethodDescription
addStylesAdd styles to the workbook styles
createCreate a new worksheet and returns a handle to it
createRangeThemeStyleCreate a range theme style
deleteActiveSheetDeletes the currently active sheet
deleteDefinedNameDelete the defined name with the given name
deleteSheetDeletes the specified worksheet
dispose-
duplicateActiveSheetDuplicates the active sheet
duplicateSheetDuplicates the given worksheet
getActiveCellReturns the active cell in this spreadsheet
getActiveRangeReturns the selected range in the active sheet, or null if there is no active range
getActiveSheetGet the active sheet of the workbook
getCustomMetadataGet custom metadata of workbook
getDefinedNameGet the defined name by name
getDefinedNamesGet all the defined names in the workbook
getIdGet the id of the workbook
getLocaleGet the locale of the workbook
getNameGet the name of the workbook
getNumSheetsGet the number of sheets in the workbook
getRegisteredRangeThemesGets the registered range themes
getSheetByNameGet a worksheet by sheet name
getSheetBySheetIdGet a worksheet by sheet id
getSheetsGets all the worksheets in this workbook
getSnapshot-
getUrlGet the URL of the workbook
getWorkbookGet the Workbook instance
getWorkbookPermissionGet the WorkbookPermission instance for managing workbook-level permissions
id-
insertDefinedNameInsert a defined name
insertDefinedNameBuilderInsert a defined name by builder param
insertSheetInserts a new worksheet into the workbook
moveActiveSheetMove the active sheet to the specified index
moveSheetMove the sheet to the specified index
onBeforeCommandExecuteCallback for command execution
onCommandExecutedCallback for command execution
onSelectionChangeCallback for selection changes
redoRedo the last undone action
registerRangeThemeRegister a custom range theme style
removeStylesRemove styles from the workbook styles
saveSave workbook snapshot data, including conditional formatting, data validation, and other plugin data
setActiveRangeSets the selection region for active sheet
setActiveSheetSets the given worksheet to be the active worksheet in the workbook
setCustomMetadataSet custom metadata of workbook
setEditableUsed to modify the editing permissions of the workbook
setLocale-
setNameSet the name of the workbook
setSpreadsheetLocaleSet the locale of the workbook
undoUndo the last action
unregisterRangeThemeUnregister a custom range theme style
updateDefinedNameBuilderUpdate the defined name with the given name

@univerjs/sheets-data-validation

@univerjs/sheets-formula

MethodDescription
getAllFormulaError-
MethodDescription
parseSheetHyperlinkParse the hyperlink string to get the hyperlink info
MethodDescription
navigateToSheetHyperlink-

@univerjs/sheets-numfmt

MethodDescription
setNumfmtLocal-

@univerjs/sheets-table

@univerjs/sheets-thread-comment

@univerjs/sheets-ui

@univerjs/sheets-zen-editor

@univerjs-pro/range-preprocess

MethodDescription
getPreprocessRanges-

@univerjs-pro/sheets-pivot

@univerjs-pro/sheets-print

@univerjs-labs/local-snapshot-manager

MethodDescription
flushToFile-

@univerjs-labs/sheets-mcp

MethodDescription
getLintErrors-
searchCells-

APIs

Sheet Operations

create

Create a new worksheet and returns a handle to it.

Signature

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

Parameters

  • name stringNo description
  • rows numberNo description
  • columns numberNo description
  • options { index?: number; sheet?: Partial<IWorksheetData>; } (optional)No description

Returns

  • FWorksheet — The new created sheet

Examples

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

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

Parameters

  • themeName stringNo description
  • themeStyleJson Omit<IRangeThemeStyleJSON, "name"> (optional)No description

Returns

  • RangeThemeStyle — - The created range theme style

Examples

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

deleteActiveSheet(): boolean

Returns

  • boolean — true if the sheet was deleted, false otherwise

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.deleteActiveSheet();
Source: @univerjs/sheets

deleteDefinedName

Delete the defined name with the given name.

Signature

deleteDefinedName(name: string): boolean

Parameters

  • name stringNo description

Returns

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

Examples

// 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

deleteSheet(sheet: FWorksheet | string): boolean

Parameters

  • sheet string | FWorksheetNo description

Returns

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

Examples

// 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

getActiveSheet(): FWorksheet

Returns

  • FWorksheet — The active sheet of the workbook

Examples

// 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

getSheetByName(name: string): FWorksheet | null

Parameters

  • name stringNo description

Returns

  • FWorksheet — The worksheet with given sheet name

Examples

// 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

getSheetBySheetId(sheetId: string): FWorksheet | null

Parameters

  • sheetId stringNo description

Returns

  • FWorksheet — The worksheet with given sheet id

Examples

// 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

getSheets(): FWorksheet[]

Returns

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

Examples

// 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

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

Parameters

  • name stringNo description
  • formulaOrRefString stringNo description

Returns

  • FWorkbook — The current FWorkbook instance

Examples

// 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

insertDefinedNameBuilder(param: ISetDefinedNameMutationParam): void

Parameters

  • param ISetDefinedNameMutationParamNo description

Examples

// The code below inserts a defined name by builder param
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameBuilder = univerAPI.newDefinedName()
  .setRef('Sheet1!$A$1')
  .setName('MyDefinedName')
  .setComment('This is a comment')
  .build();
fWorkbook.insertDefinedNameBuilder(definedNameBuilder);
Source: @univerjs/sheets

insertSheet

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

Signature

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

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

getDefinedName(name: string): FDefinedName | null

Parameters

  • name stringNo description

Returns

  • FDefinedName — The defined name with the given name

Examples

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

if (definedName) {
  definedName.setName('NewDefinedName');
}
Source: @univerjs/sheets

getDefinedNames

Get all the defined names in the workbook.

Signature

getDefinedNames(): FDefinedName[]

Returns

  • FDefinedName[] — All the defined names in the workbook

Examples

// 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

getName(): string

Returns

  • string — The name of the workbook.

Examples

// 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

getTableInfoByName(tableName: string): ITableInfoWithUnitId | undefined

Parameters

  • tableName stringNo description

Returns

  • any — See signature above.
Source: @univerjs/sheets-table

setName

Set the name of the workbook.

Signature

setName(name: string): this

Parameters

  • name stringNo description

Returns

  • this — See signature above.

Examples

// 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

updateDefinedNameBuilder(param: ISetDefinedNameMutationParam): void

Parameters

  • param ISetDefinedNameMutationParamNo description

Examples

// 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

getRegisteredRangeThemes(): string[]

Returns

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

Examples

// 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

registerRangeTheme(rangeThemeStyle: RangeThemeStyle): void

Parameters

  • rangeThemeStyle RangeThemeStyleNo description

Examples

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

unregisterRangeTheme(themeName: string): void

Parameters

  • themeName stringNo description

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.unregisterRangeTheme('MyTheme');
Source: @univerjs/sheets

Collaboration

getSnapshot

Deprecated — use 'save' instead.

Signature

getSnapshot(): IWorkbookData

Returns

  • IWorkbookData — Workbook snapshot data

Tags

  • @memberof — FWorkbook

Examples

// The code below saves the workbook snapshot data
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const snapshot = activeSpreadsheet.getSnapshot();
Source: @univerjs/sheets

Pivot Tables

addPivotTable

Signature

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

Parameters

  • sourceInfo anyNo description
  • positionType PositionTypeNo description
  • anchorCellInfo IPivotCellPositionInfoNo description

Returns

  • Promise<FPivotTable> — See signature above.
Source: @univerjs-pro/sheets-pivot

getPivotTableByCell

Signature

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

Parameters

  • unitId stringNo description
  • subUnitId stringNo description
  • row numberNo description
  • col numberNo description

Returns

  • FPivotTable — See signature above.
Source: @univerjs-pro/sheets-pivot

getPivotTableById

Signature

getPivotTableById(pivotTableId: string): FPivotTable | undefined

Parameters

  • pivotTableId stringNo description

Returns

  • FPivotTable — See signature above.
Source: @univerjs-pro/sheets-pivot

Miscellaneous

abortEditingAsync

Signature

abortEditingAsync(): Promise<boolean>

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-ui

addStyles

Add styles to the workbook styles.

Signature

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

Parameters

  • styles Record<string, IStyleData>No description

Examples

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

clearComments(): Promise<boolean>

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-thread-comment

customizeColumnHeader

Signature

customizeColumnHeader(cfg: IColumnsHeaderCfgParam): void

Parameters

  • cfg IColumnsHeaderCfgParamNo description
Source: @univerjs/sheets-ui

customizeRowHeader

Signature

customizeRowHeader(cfg: IRowsHeaderCfgParam): void

Parameters

  • cfg IRowsHeaderCfgParamNo description
Source: @univerjs/sheets-ui

disableSelection

Signature

disableSelection(): FWorkbook

Returns

  • FWorkbook — See signature above.
Source: @univerjs/sheets-ui

dispose

Signature

dispose(): void
Source: @univerjs/sheets

duplicateActiveSheet

Duplicates the active sheet.

Signature

duplicateActiveSheet(): FWorksheet

Returns

  • FWorksheet — The duplicated worksheet

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const duplicatedSheet = fWorkbook.duplicateActiveSheet();
console.log(duplicatedSheet);
Source: @univerjs/sheets

duplicateSheet

Duplicates the given worksheet.

Signature

duplicateSheet(sheet: FWorksheet): FWorksheet

Parameters

  • sheet FWorksheetNo description

Returns

  • FWorksheet — The duplicated worksheet

Examples

// 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

enableSelection(): FWorkbook

Returns

  • FWorkbook — See signature above.
Source: @univerjs/sheets-ui

endEditing

Signature

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

Parameters

  • save boolean (optional)No description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-ui

endEditingAsync

Signature

endEditingAsync(save = true): Promise<boolean>

Parameters

  • save boolean (optional)No description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-ui

endZenEditingAsync

Signature

endZenEditingAsync(save = true): Promise<boolean>

Parameters

  • save boolean (optional)No description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-zen-editor

flushToFile

Signature

async flushToFile(): Promise<void>

Returns

  • Promise<void> — See signature above.
Source: @univerjs-labs/local-snapshot-manager

getActiveCell

Returns the active cell in this spreadsheet.

Signature

getActiveCell(): FRange | null

Returns

  • FRange — The active cell

Examples

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

getActiveRange(): FRange | null

Returns

  • FRange — The active range

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const activeRange = fWorkbook.getActiveRange();
console.log(activeRange);
Source: @univerjs/sheets

getAllDataValidationErrorAsync

Signature

async getAllDataValidationErrorAsync(): Promise<IDataValidationError[]>

Returns

  • Promise<IDataValidationError[]> — See signature above.
Source: @univerjs/sheets-data-validation

getAllFormulaError

Signature

getAllFormulaError(): ISheetFormulaError[]

Returns

  • ISheetFormulaError[] — See signature above.
Source: @univerjs/sheets-formula

getComments

Signature

getComments(): FThreadComment[]

Returns

  • FThreadComment[] — See signature above.
Source: @univerjs/sheets-thread-comment

getCustomMetadata

Get custom metadata of workbook

Signature

getCustomMetadata(): CustomData | undefined

Returns

  • CustomData — custom metadata

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
const custom = fWorkbook.getCustomMetadata();
console.log(custom);
Source: @univerjs/sheets

getId

Get the id of the workbook.

Signature

getId(): string

Returns

  • string — The id of the workbook.

Examples

// The code below gets the id of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook.getId();
console.log(unitId);
Source: @univerjs/sheets

getLintErrors

Signature

async getLintErrors(): Promise<ILintErrorReport>

Returns

  • Promise<ILintErrorReport> — See signature above.
Source: @univerjs-labs/sheets-mcp

getLocale

Get the locale of the workbook.

Signature

getLocale(): LocaleType

Returns

  • LocaleType — The locale of the workbook

Examples

// 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

getNumSheets(): number

Returns

  • number — The number of sheets in the workbook

Examples

// The code below gets the number of sheets in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getNumSheets());
Source: @univerjs/sheets

getPreprocessRanges

Signature

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

Parameters

  • responseDataMode string (optional)No description

Returns

  • Record<string, ITableJson[]> — See signature above.
Source: @univerjs-pro/range-preprocess

getScrollStateBySheetId

Get scroll state of specified sheet.

Signature

getScrollStateBySheetId(sheetId: string): Nullable<IScrollState>

Parameters

  • sheetId stringNo description

Returns

  • any — scroll state

Examples

 ts
univerAPI.getActiveWorkbook().getScrollStateBySheetId($sheetId)
Source: @univerjs/sheets-ui

getUrl

Get the URL of the workbook.

Signature

getUrl(): string

Returns

  • string — The URL of the workbook

Examples

// 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

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

getWorkbook(): Workbook

Returns

  • Workbook — The Workbook instance.

Examples

// 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

getWorkbookPermission(): FWorkbookPermission

Returns

  • FWorkbookPermission — - The WorkbookPermission instance.

Examples

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

id: string

Returns

  • string — See signature above.
Source: @univerjs/sheets

isCellEditing

Signature

isCellEditing(): boolean

Returns

  • boolean — See signature above.
Source: @univerjs/sheets-ui

moveActiveSheet

Move the active sheet to the specified index.

Signature

moveActiveSheet(index: number): FWorkbook

Parameters

  • index numberNo description

Returns

  • FWorkbook — This workbook, for chaining

Examples

// 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

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

Parameters

  • sheet FWorksheetNo description
  • index numberNo description

Returns

  • FWorkbook — This workbook, for chaining

Examples

// 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

Signature

navigateToSheetHyperlink(hyperlink: string): void

Parameters

  • hyperlink stringNo description
Source: @univerjs/sheets-hyper-link-ui

onBeforeAddDataValidation

Signature

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

Parameters

  • callback (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeAddThreadComment

Deprecated — Deprecated

Signature

onBeforeAddThreadComment(callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable

Parameters

  • callback (params: IAddCommentCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-thread-comment

onBeforeCommandExecute

Callback for command execution.

Signature

onBeforeCommandExecute(callback: CommandListener): IDisposable

Parameters

  • callback CommandListenerNo description

Returns

  • IDisposable — See signature above.

Tags

  • @callback — onBeforeCommandExecuteCallback
Source: @univerjs/sheets

onBeforeDeleteAllDataValidation

Signature

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

Parameters

  • callback (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeDeleteDataValidation

Signature

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

Parameters

  • callback (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeDeleteThreadComment

Deprecated — Deprecated

Signature

onBeforeDeleteThreadComment(callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable

Parameters

  • callback (params: IDeleteCommentCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-thread-comment

onBeforeUpdateDataValidationCriteria

Signature

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

Parameters

  • callback (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeUpdateDataValidationOptions

Signature

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

Parameters

  • callback (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeUpdateDataValidationRange

Signature

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

Parameters

  • callback (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onBeforeUpdateThreadComment

Deprecated — Deprecated

Signature

onBeforeUpdateThreadComment(callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable

Parameters

  • callback (params: any, options: IExecutionOptions) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-thread-comment

onCellClick

Signature

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

Parameters

  • callback (cell: IHoverRichTextInfo) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onCellHover

Signature

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

Parameters

  • callback (cell: IHoverRichTextPosition) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onCellPointerDown

Signature

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

Parameters

  • callback (cell: ICellPosWithEvent) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onCellPointerMove

Signature

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

Parameters

  • callback (cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onCellPointerUp

Signature

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

Parameters

  • callback (cell: ICellPosWithEvent) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onCommandExecuted

Callback for command execution.

Signature

onCommandExecuted(callback: CommandListener): IDisposable

Parameters

  • callback CommandListenerNo description

Returns

  • IDisposable — See signature above.

Tags

  • @callback — onCommandExecutedCallback
Source: @univerjs/sheets

onDataValidationChange

Signature

onDataValidationChange(callback: (ruleChange: IRuleChange) => void): IDisposable

Parameters

  • callback (ruleChange: IRuleChange) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onDataValidationStatusChange

Signature

onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable

Parameters

  • callback (statusChange: IValidStatusChange) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-data-validation

onDragOver

Signature

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

Parameters

  • callback (cell: IDragCellPosition) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onDrop

Signature

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

Parameters

  • callback (cell: IDragCellPosition) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

onSelectionChange

Callback for selection changes.

Signature

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

Parameters

  • callback (selections: IRange[]) => voidNo description

Returns

  • IDisposable — See signature above.

Tags

  • @callback — onSelectionChangeCallback
Source: @univerjs/sheets

onThreadCommentChange

Deprecated — Deprecated

Signature

onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable

Parameters

  • callback (commentUpdate: CommentUpdate) => false | voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-thread-comment

openDialog

Signature

openDialog(dialog: IDialogPartMethodOptions): IDisposable

Parameters

  • dialog IDialogPartMethodOptionsNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

openSiderbar

Signature

openSiderbar(params: ISidebarMethodOptions): IDisposable

Parameters

  • params ISidebarMethodOptionsNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/sheets-ui

Parse the hyperlink string to get the hyperlink info.

Signature

parseSheetHyperlink(hyperlink: string): ISheetHyperLinkInfo

Parameters

  • hyperlink stringNo description

Returns

  • ISheetHyperLinkInfo — the hyperlink info
Source: @univerjs/sheets-hyper-link

redo

Redo the last undone action.

Signature

redo(): FWorkbook

Returns

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

Examples

// 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

removeStyles(styleKeys: string[]): void

Parameters

  • styleKeys string[]No description

Examples

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

save(): IWorkbookData

Returns

  • IWorkbookData — Workbook snapshot data

Examples

// The code below saves the workbook snapshot data
const fWorkbook = univerAPI.getActiveWorkbook();
const snapshot = fWorkbook.save();
console.log(snapshot);
Source: @univerjs/sheets

saveScreenshotToClipboard

Signature

async saveScreenshotToClipboard(): Promise<boolean>

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs-pro/sheets-print

searchCells

Signature

searchCells(text: string | string[], options: ICustomSearchCellsOptions = {}): ICustomSearchCellsResult[]

Parameters

  • text string | string[]No description
  • options ICustomSearchCellsOptions (optional)No description

Returns

  • ICustomSearchCellsResult[] — See signature above.
Source: @univerjs-labs/sheets-mcp

setActiveRange

Sets the selection region for active sheet.

Signature

setActiveRange(range: FRange): FWorkbook

Parameters

  • range FRangeNo description

Returns

  • FWorkbook — FWorkbook instance

Examples

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

setActiveSheet(sheet: FWorksheet | string): FWorksheet

Parameters

  • sheet string | FWorksheetNo description

Returns

  • FWorksheet — The active worksheet

Examples

// 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

setCustomMetadata(custom: CustomData | undefined): FWorkbook

Parameters

  • custom CustomData — metadata

Returns

  • FWorkbook — FWorkbook

Examples

const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setCustomMetadata({ key: 'value' });
Source: @univerjs/sheets

setLocale

Deprecated — use setSpreadsheetLocale instead.

Signature

setLocale(locale: LocaleType): void

Parameters

  • locale LocaleTypeNo description
Source: @univerjs/sheets

setNumfmtLocal

Signature

setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook

Parameters

  • locale INumfmtLocaleTagNo description

Returns

  • FWorkbook — See signature above.
Source: @univerjs/sheets-numfmt

setPermissionDialogVisible

Signature

setPermissionDialogVisible(visible: boolean): void

Parameters

  • visible booleanNo description
Source: @univerjs/sheets-ui

setSpreadsheetLocale

Set the locale of the workbook.

Signature

setSpreadsheetLocale(locale: LocaleType): FWorkbook

Parameters

  • locale LocaleTypeNo description

Returns

  • FWorkbook — This workbook, for chaining

Examples

// 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

showSelection(): FWorkbook

Returns

  • FWorkbook — See signature above.
Source: @univerjs/sheets-ui

startEditing

Signature

startEditing(): boolean

Returns

  • boolean — See signature above.
Source: @univerjs/sheets-ui

startZenEditingAsync

Signature

startZenEditingAsync(): Promise<boolean>

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-zen-editor

transparentSelection

Signature

transparentSelection(): FWorkbook

Returns

  • FWorkbook — See signature above.
Source: @univerjs/sheets-ui

undo

Undo the last action.

Signature

undo(): FWorkbook

Returns

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

Examples

// The code below undoes the last action
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.undo();
Source: @univerjs/sheets

Print

closePrintDialog

Signature

closePrintDialog(): void
Source: @univerjs-pro/sheets-print

openPrintDialog

Signature

openPrintDialog(): void
Source: @univerjs-pro/sheets-print

Signature

print(): void
Source: @univerjs-pro/sheets-print

updatePrintConfig

Signature

updatePrintConfig(config: ISheetPrintLayoutConfig): FWorkbook

Parameters

  • config ISheetPrintLayoutConfigNo description

Returns

  • FWorkbook — See signature above.
Source: @univerjs-pro/sheets-print

updatePrintRenderConfig

Signature

updatePrintRenderConfig(config: ISheetPrintRenderConfig): FWorkbook

Parameters

  • config ISheetPrintRenderConfigNo description

Returns

  • FWorkbook — See signature above.
Source: @univerjs-pro/sheets-print

Tables

addTable

Signature

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

Parameters

  • subUnitId stringNo description
  • tableName stringNo description
  • rangeInfo ITableRangeNo description
  • tableId string (optional)No description
  • options ITableOptions (optional)No description

Returns

  • Promise<string> — See signature above.
Source: @univerjs/sheets-table

getTableInfo

Signature

getTableInfo(tableId: string): ITableInfoWithUnitId | undefined

Parameters

  • tableId stringNo description

Returns

  • any — See signature above.
Source: @univerjs/sheets-table

getTableList

Signature

getTableList(): ITableInfoWithUnitId[]

Returns

  • ITableInfoWithUnitId[] — See signature above.
Source: @univerjs/sheets-table

removeTable

Signature

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

Parameters

  • tableId stringNo 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

setEditable(value: boolean): FWorkbook

Parameters

  • value booleanNo description

Returns

  • FWorkbook — FWorkbook instance

Examples

// The code below sets the editing permissions of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setEditable(false);
Source: @univerjs/sheets

setTableFilter

Signature

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

Parameters

  • tableId stringNo description
  • column numberNo description
  • filter anyNo description

Returns

  • Promise<boolean> — See signature above.
Source: @univerjs/sheets-table

Table of Contents

Overview
@univerjs/sheets
@univerjs/sheets-data-validation
@univerjs/sheets-formula
@univerjs/sheets-hyper-link
@univerjs/sheets-hyper-link-ui
@univerjs/sheets-numfmt
@univerjs/sheets-table
@univerjs/sheets-thread-comment
@univerjs/sheets-ui
@univerjs/sheets-zen-editor
@univerjs-pro/range-preprocess
@univerjs-pro/sheets-pivot
@univerjs-pro/sheets-print
@univerjs-labs/local-snapshot-manager
@univerjs-labs/sheets-mcp
APIs
Sheet Operations
create
createRangeThemeStyle
deleteActiveSheet
deleteDefinedName
deleteSheet
getActiveSheet
getSheetByName
getSheetBySheetId
getSheets
insertDefinedName
insertDefinedNameBuilder
insertSheet
Defined Names
getDefinedName
getDefinedNames
getName
getTableInfoByName
setName
updateDefinedNameBuilder
Range Themes
getRegisteredRangeThemes
registerRangeTheme
unregisterRangeTheme
Collaboration
getSnapshot
Pivot Tables
addPivotTable
getPivotTableByCell
getPivotTableById
Miscellaneous
abortEditingAsync
addStyles
clearComments
customizeColumnHeader
customizeRowHeader
disableSelection
dispose
duplicateActiveSheet
duplicateSheet
enableSelection
endEditing
endEditingAsync
endZenEditingAsync
flushToFile
getActiveCell
getActiveRange
getAllDataValidationErrorAsync
getAllFormulaError
getComments
getCustomMetadata
getId
getLintErrors
getLocale
getNumSheets
getPreprocessRanges
getScrollStateBySheetId
getUrl
getValidatorStatus
getWorkbook
getWorkbookPermission
id
isCellEditing
moveActiveSheet
moveSheet
navigateToSheetHyperlink
onBeforeAddDataValidation
onBeforeAddThreadComment
onBeforeCommandExecute
onBeforeDeleteAllDataValidation
onBeforeDeleteDataValidation
onBeforeDeleteThreadComment
onBeforeUpdateDataValidationCriteria
onBeforeUpdateDataValidationOptions
onBeforeUpdateDataValidationRange
onBeforeUpdateThreadComment
onCellClick
onCellHover
onCellPointerDown
onCellPointerMove
onCellPointerUp
onCommandExecuted
onDataValidationChange
onDataValidationStatusChange
onDragOver
onDrop
onSelectionChange
onThreadCommentChange
openDialog
openSiderbar
parseSheetHyperlink
redo
removeStyles
save
saveScreenshotToClipboard
searchCells
setActiveRange
setActiveSheet
setCustomMetadata
setLocale
setNumfmtLocal
setPermissionDialogVisible
setSpreadsheetLocale
showSelection
startEditing
startZenEditingAsync
transparentSelection
undo
Print
closePrintDialog
openPrintDialog
print
updatePrintConfig
updatePrintRenderConfig
Tables
addTable
getTableInfo
getTableList
removeTable
setEditable
setTableFilter
Capalyze