Univer Sheets API

Univer Sheets provides professional-grade spreadsheet capabilities, with concepts designed to be as consistent as possible with Microsoft Excel.

Importing

TypeScript
import '@univerjs/sheets/facade'import '@univerjs/sheets-ui/facade'

Workbook

A workbook contains multiple worksheets and can be thought of as an Excel file.

The unitId can be used as a unique identifier for the workbook.

Create a Workbook

The univerAPI.createWorkbook(data, options) method creates and returns the FWorkbook object.

The IWorkbookData is an object that contains the configuration information of the workbook.

TypeScript
const fWorkbook = univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' })console.log(fWorkbook)

Add you can make the workbook not as the active workbook by setting options:

TypeScript
const fWorkbook = univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' }, { makeCurrent: false })console.log(fWorkbook)// If you want to switch to this workbook after 3 secondssetTimeout(() => {  univerAPI.setCurrent(fWorkbook.getId())}, 3000)

Get Workbook Data

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const snapshot = fWorkbook.save()console.log(snapshot)

Unload Workbook

When you no longer need a Workbook, you can call the disposeUnit method on the API instance to unload it.

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const unitId = fWorkbook?.getId()if (unitId) {  univerAPI.disposeUnit(unitId)}

When the entire page hosting the Univer instance is destroyed or the route is unloaded, make sure to call the univer.dispose() method for cleanup, rather than using univerAPI.disposeUnit. Also, please note that univer and univerAPI are different instances. For instructions on how to obtain these instances, refer to the Installation & Basic Usage.

Get Workbook ID

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook?.getId()

Worksheet

Worksheets store table data, worksheets belong to the workbook.

A workbook can contain multiple worksheets, and the names of worksheets in the same workbook cannot be duplicated.

The subUnitId can be used to uniquely identify a sheet in a workbook.

Get Worksheets

Get all sheets in a sheet

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const sheets = fWorkbook.getSheets()

Get Active Worksheet

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()

Get Worksheet Data

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const sheetSnapshot = fWorksheet.getSheet().getSnapshot()

Create a Worksheet

The following example shows how to create a worksheet using the FWorkbook.create method.

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()// Create a worksheet named 'Sheet2' with 10 rows and 10 columnsconst newSheet = fWorkbook.create('Sheet2', 10, 10)// 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)

Remove Worksheet

Remove Worksheet by passing the worksheet instance or the worksheet Id

TypeScript
// Delete the second 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());

Activate Worksheet

Activate the worksheet by passing the worksheet instance or the worksheet Id, or use FWorksheet.activate() method.

TypeScript
// Activate the second worksheetconst fWorkbook = univerAPI.getActiveWorkbook()const sheet = fWorkbook.getSheets()[1]fWorkbook.setActiveSheet(sheet)// Activates the specified worksheet by id// fWorkbook.setActiveSheet(sheet.getSheetId());// Activate the worksheet using the FWorksheet.activate() method// sheet.activate();

Copy Worksheet

TypeScript
// The code below duplicates the given worksheetconst fWorkbook = univerAPI.getActiveWorkbook()const activeSheet = fWorkbook.getActiveSheet()const duplicatedSheet = fWorkbook.duplicateSheet(activeSheet)console.log(duplicatedSheet)

Get Worksheet ID

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()fWorksheet?.getSheetId()

Set Worksheet Row and Column Count

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Set row count to 100000fWorksheet.setRowCount(100000)// Set column count to 30fWorksheet.setColumnCount(30)

Refresh Worksheet

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()fWorksheet.refreshCanvas()

Worksheet Zoom

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Set zoom ratio to 200%fWorksheet.zoom(2)const zoomRatio = fWorksheet.getZoom()

Scroll to Cell

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()// Scroll to cell D10const fRange = fWorksheet.getRange('D10')const row = fRange.getRow()const column = fRange.getColumn()fWorksheet.scrollToCell(row, column)// Add scroll animation durationfWorksheet.scrollToCell(row, column, 1000)// Get scroll stateconst scrollState = fWorksheet.getScrollState()const { offsetX, offsetY, sheetViewStartColumn, sheetViewStartRow } = scrollStateconsole.log(scrollState) // sheetViewStartRow: 9, sheetViewStartColumn: 3, offsetX: 0, offsetY: 0

Core Features

Permission

Reference: Permission

Formula

Reference: Formula

Row and Column

Reference: Row and Column

Range

Reference: Range

Selection

Reference: Selection

Cell

Reference: Cell

Freeze

Reference: Freeze

Integrating Custom Components into Univer

Reference: Integrating Custom Components into Univer

Reference

Please refer to the following API documentation for more information:

How is this guide?

© 2026 DreamNum Co., Ltd.