FWorksheet
A Facade API object bounded to a worksheet. It provides a set of methods to interact with the worksheet.
Get this object from the initialized univerAPI instance. The example assumes a workbook is already open.
const sheet = univerAPI.getActiveWorkbook()?.getActiveSheet()if (!sheet) throw new Error('No active worksheet')sheet.getRange('A1').setValue('Hello, Univer!')Access
Access through:
FWorkbook.getActiveSheet()FWorkbook.getSheets()FWorkbook.create()FWorkbook.getSheetBySheetId()FWorkbook.getSheetByName()FWorkbook.setActiveSheet()FWorkbook.insertSheet()FWorkbook.duplicateSheet()
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
FWorksheet.activate
Activates this sheet. Does not alter the sheet itself, only the parent's notion of the active sheet.
activate(): FWorksheetReturns
Current sheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheets = fWorkbook.getSheets()// activate the last sheetfWorkSheets[fWorkSheets.length - 1].activate()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.appendRow
Appends a row to the bottom of the current data region in the sheet. If the destination row is already within the worksheet capacity,
this method writes into that row without increasing getMaxRows(). If a cell's content begins with =, it's interpreted as a formula.
appendRow(rowContents: CellValue[]): FWorksheetParameters
rowContents— Required. An array of values for the new row.
Returns
Returns the current worksheet instance for method chaining.
Examples
// Appends a new row with 4 columns to the bottom of the current// data region in the sheet containing the values in the array.const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.appendRow([1, 'Hello Univer', true, '=A1'])Types: FWorksheet · CellValue
Package: @univerjs/sheets · Type definitions
FWorksheet.autoFitRow
Make certain row wrap and auto height.
autoFitRow(rowPosition: number, auto?: BooleanNumber): FWorksheetParameters
rowPosition— Required. The row position to change.auto— Optional. Default:BooleanNumber.TRUE. Whether to auto fit the row height.
Returns
This worksheet instance for chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.autoFitRow(24)Types: FWorksheet · BooleanNumber
Package: @univerjs/sheets · Type definitions
FWorksheet.cancelFreeze
Cancels the frozen state of the current sheet.
cancelFreeze(): FWorksheetReturns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Cancel freezefWorksheet.cancelFreeze()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.clear
Clears the sheet content and formatting, or only one of them as specified by the options. Both content and formatting are cleared when both flags are true or both are false.
clear(options?: IFacadeClearOptions): FWorksheetParameters
options— Optional. Options for clearing the sheet. If not provided, the contents and formatting are cleared both.
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// clear the sheet of content and formatting informationfWorkSheet.clear()// clear the sheet of content onlyfWorkSheet.clear({ contentsOnly: true })Types: FWorksheet · IFacadeClearOptions
Package: @univerjs/sheets · Type definitions
FWorksheet.clearContents
Clears the sheet of contents, while preserving formatting information.
clearContents(): FWorksheetReturns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// clear the sheet of content onlyfWorkSheet.clearContents()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.clearFormats
Clears the sheet of formatting, while preserving contents.
clearFormats(): FWorksheetReturns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// clear the sheet of formatting onlyfWorkSheet.clearFormats()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteColumn
Deletes the column at the given column position.
deleteColumn(columnPosition: number): FWorksheetParameters
columnPosition— Required. The position of the column, starting at 0 for the first column
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete column CfWorksheet.deleteColumn(2)// Delete column AfWorksheet.deleteColumn(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteColumns
Deletes a number of columns starting at the given column position.
deleteColumns(columnPosition: number, howMany: number): FWorksheetParameters
columnPosition— Required. The position of the first column to delete, starting at 0 for the first columnhowMany— Required. The number of columns to delete
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete 3 columns at column index 2 (columns C, D, E)fWorksheet.deleteColumns(2, 3)// Delete 1 column at column index 0 (column A)fWorksheet.deleteColumns(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteColumnsByPoints
Deletes the columns specified by the given column points. Each point can be a single column index or a tuple representing a range of columns.
deleteColumnsByPoints(columnPoints: Array<number | [number, number]>): FWorksheetParameters
columnPoints— Required. An array of column points to delete. Each point can be a single column index or a tuple representing a range of columns.
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete columns at index 2, and range from index 4 to 6 (columns C, E-G)fWorksheet.deleteColumnsByPoints([2, [4, 6]])Types: FWorksheet · Array
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteRow
Deletes the row at the given row position.
deleteRow(rowPosition: number): FWorksheetParameters
rowPosition— Required. The position of the row, starting at 0 for the first row.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete the third rowfWorksheet.deleteRow(2)// Delete the first rowfWorksheet.deleteRow(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteRows
Deletes a number of rows starting at the given row position.
deleteRows(rowPosition: number, howMany: number): FWorksheetParameters
rowPosition— Required. The position of the first row to delete, starting at 0 for the first row.howMany— Required. The number of rows to delete.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete 3 rows at row index 2 (rows 3-5)fWorksheet.deleteRows(2, 3)// Delete 1 row at row index 0 (first row)fWorksheet.deleteRows(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.deleteRowsByPoints
Deletes the rows specified by the given row points. Each point can be a single row index or a tuple representing a range of rows.
deleteRowsByPoints(rowPoints: Array<number | [number, number]>): FWorksheetParameters
rowPoints— Required. An array of row points to delete. Each point can be a single row index or a tuple representing a range of rows.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Delete rows at index 2, and range from index 4 to 6 (rows 3, 5-7)fWorksheet.deleteRowsByPoints([2, [4, 6]])Types: FWorksheet · Array
Package: @univerjs/sheets · Type definitions
FWorksheet.dispose
Releases this facade's resources. Use univerAPI.disposeUnit() to unload the owning unit.
dispose(): voidPackage: @univerjs/sheets · Type definitions
FWorksheet.equalTo
Judge whether provided FWorksheet is equal to current.
equalTo(other: FWorksheet): booleanParameters
other— Required. the FWorksheet to compare with.
Returns
true if the FWorksheet is equal to the current FWorksheet, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const sheets = fWorkbook.getSheets()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')console.log(fWorkSheet.equalTo(sheets[0])) // true, if the active sheet is the first sheet.Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.getActiveCell
Returns the active cell in this sheet.
getActiveCell(): FRange | nullReturns
The active cell
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')console.log(fWorkSheet.getActiveCell().getA1Notation())Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getActiveRange
Returns the selected range in the active sheet, or null if there is no active range.
getActiveRange(): FRange | nullReturns
the active range
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get the currently active rangeconst activeRange = fWorksheet.getActiveRange()if (activeRange) { console.log('Active range:', activeRange.getA1Notation())}Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getCellMergeData
Get the merged cell data of the specified row and column.
getCellMergeData(row: number, column: number): FRange | undefinedParameters
row— Required. The row indexcolumn— Required. The column index
Returns
The merged cell data, or undefined if the cell is not merged
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')const merge = fWorkSheet.getCellMergeData(0, 0)if (merge) { console.log('Merged range:', merge.getA1Notation())}Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getColumnCustomMetadata
Get custom metadata of column
getColumnCustomMetadata(index: number): CustomData | undefinedParameters
index— Required. column index
Returns
custom metadata
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')const custom = fWorkSheet.getColumnCustomMetadata(0)console.log(custom)Types: CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.getColumnDefaultStyle
Get the default style of the worksheet column
getColumnDefaultStyle(index: number, keepRaw?: boolean): Nullable<IStyleData> | stringParameters
index— Required. The column indexkeepRaw— Optional. Default:false. If true, return the raw style data maybe the style name or style data, otherwise return the data from col manager
Returns
The default style of the worksheet column name or style data
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get default style for column 0 (A)const colStyle = fWorksheet.getColumnDefaultStyle(0)console.log(colStyle)// Get raw style data for column 0const rawColStyle = fWorksheet.getColumnDefaultStyle(0, true)console.log(rawColStyle)Types: Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.getColumnWidth
Gets the width in pixels of the given column.
getColumnWidth(columnPosition: number): numberParameters
columnPosition— Required. The position of the column to examine. index starts at 0.
Returns
The width of the column in pixels
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set the long text value in cell A1const fRange = fWorksheet.getRange('A1')fRange.setValue('Whenever it is a damp, drizzly November in my soul...')// Set the column A to a width which fits the textfWorksheet.autoResizeColumns(0)// Get the width of the column Aconsole.log(fWorksheet.getColumnWidth(0))Package: @univerjs/sheets · Type definitions
FWorksheet.getCustomMetadata
Get custom metadata of worksheet
getCustomMetadata(): CustomData | undefinedReturns
custom metadata
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')const custom = fWorkSheet.getCustomMetadata()console.log(custom)Types: CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.getDataRange
Returns a Range corresponding to the dimensions in which data is present. Empty cells with style or formatting will also be included in the data range. If there is no data on the sheet, returns a Range corresponding to the top-left cell of the sheet (A1).
getDataRange(): FRangeReturns
The range of the data in the sheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Assume the sheet is a empty sheetconst cellRange = fWorkSheet.getRange('J50')cellRange.setValue('Hello World')console.log(fWorkSheet.getDataRange().getA1Notation()) // A1:J50Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getDefaultStyle
Get the default style of the worksheet.
getDefaultStyle(): Nullable<IStyleData> | stringReturns
The default style object or style ID, or a nullish value when no default style is set.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const defaultStyle = fWorksheet.getDefaultStyle()console.log(defaultStyle)Types: Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.getDefinedNames
Get all the defined names in the worksheet.
getDefinedNames(): FDefinedName[]Returns
All the defined names in the worksheet
Examples
// The code below gets all the defined names in the worksheetconst fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const definedNames = fWorksheet.getDefinedNames()console.log(definedNames, definedNames[0]?.getFormulaOrRefString())Types: FDefinedName
Package: @univerjs/sheets · Type definitions
FWorksheet.getFreeze
Get the freeze state of the current sheet.
getFreeze(): IFreezeReturns
The freeze state of the current sheet
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get the freeze state of the current sheetconst freeze = fWorksheet.getFreeze()console.log(freeze)Types: IFreeze
Package: @univerjs/sheets · Type definitions
FWorksheet.getFrozenColumnRange
Get freezed columns
getFrozenColumnRange(): IColumnRangeReturns
The range of the frozen columns.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Get the range of the frozen columnsconst frozenColumns = fWorkSheet.getFrozenColumnRange()console.log(frozenColumns)Types: IColumnRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getFrozenColumns
Get the number of frozen columns.
getFrozenColumns(): numberReturns
The number of frozen columns, returns 0 if no columns are frozen.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Get the number of frozen columnsconst frozenColumns = fWorkSheet.getFrozenColumns()console.log(frozenColumns)Package: @univerjs/sheets · Type definitions
FWorksheet.getFrozenRowRange
Get freezed rows.
getFrozenRowRange(): IRowRangeReturns
The range of the frozen rows.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Get the range of the frozen rowsconst frozenRows = fWorkSheet.getFrozenRowRange()console.log(frozenRows)Types: IRowRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getFrozenRows
Get the number of frozen rows.
getFrozenRows(): numberReturns
The number of frozen rows. returns 0 if no rows are frozen.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Get the number of frozen rowsconst frozenRows = fWorkSheet.getFrozenRows()console.log(frozenRows)Package: @univerjs/sheets · Type definitions
FWorksheet.getGridLinesColor
Get the color of the gridlines in the sheet.
getGridLinesColor(): string | undefinedReturns
The color of the gridlines in the sheet or undefined. The default color is 'rgb(214, 216, 219)'.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// get the gridlines color of the sheetconsole.log(fWorkSheet.getGridLinesColor())Package: @univerjs/sheets · Type definitions
FWorksheet.getHiddenState
Returns 0 (visible), 1 (hidden), or 2 (very hidden).
getHiddenState(): WorksheetHiddenStateExamples
fWorksheet.getHiddenState() === univerAPI.Enum.WorksheetHiddenState.VERY_HIDDEN
Types: WorksheetHiddenState
Package: @univerjs/sheets · Type definitions
FWorksheet.getIndex
Gets the position of the sheet in its parent spreadsheet. Starts at 0.
getIndex(): numberReturns
The position of the sheet in its parent spreadsheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// get the position of the active sheetconst position = fWorkSheet.getIndex()console.log(position)Package: @univerjs/sheets · Type definitions
FWorksheet.getInject
Get the injector instance.
getInject(): InjectorReturns
The injector instance.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const injector = fWorksheet.getInject()console.log(injector)Types: Injector
Package: @univerjs/sheets · Type definitions
FWorksheet.getLastColumn
Returns the zero-based index of the last column with stored cell data, including formatting-only cells.
getLastColumn(): numberReturns
The last stored column index, or 0 for an empty sheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Assume the sheet is a empty sheetconst cellRange = fWorkSheet.getRange('J50')cellRange.setValue('Hello World')console.log(fWorkSheet.getLastColumn()) // 9Package: @univerjs/sheets · Type definitions
FWorksheet.getLastRow
Returns the zero-based index of the last row with stored cell data, including formatting-only cells.
getLastRow(): numberReturns
The last stored row index, or 0 for an empty sheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Assume the sheet is a empty sheetconst cellRange = fWorkSheet.getRange('J50')cellRange.setValue('Hello World')console.log(fWorkSheet.getLastRow()) // 49Package: @univerjs/sheets · Type definitions
FWorksheet.getMaxColumns
Returns the current number of columns in the sheet, regardless of content.
getMaxColumns(): numberReturns
The maximum columns count of the sheet
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const totalColumns = fWorksheet.getMaxColumns()console.log(`Sheet has ${totalColumns} columns`)Package: @univerjs/sheets · Type definitions
FWorksheet.getMaxRows
Returns the current number of rows in the sheet, regardless of content.
getMaxRows(): numberReturns
The maximum rows count of the sheet
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const totalRows = fWorksheet.getMaxRows()console.log(`Sheet has ${totalRows} rows`)Package: @univerjs/sheets · Type definitions
FWorksheet.getMergeData
Get all merged cells in the current worksheet
getMergeData(): FRange[]Returns
All the merged cells in the worksheet
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get all merged ranges in the sheetconst mergedData = fWorksheet.getMergeData()// Process each merged rangemergedData.forEach((range) => { console.log(range.getA1Notation())})Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getMergedRanges
Get all merged cells in the current sheet
getMergedRanges(): FRange[]Returns
all merged cells
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get all merged ranges in the sheetconst mergedRanges = fWorksheet.getMergedRanges()// Process each merged rangemergedRanges.forEach((range) => { console.log(range.getA1Notation())})Types: FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.getRange
Returns a Range object representing a single cell at the specified row and column.
getRange(row: number, column: number): FRangegetRange(row: number, column: number, numRows: number): FRangegetRange(row: number, column: number, numRows: number, numColumns: number): FRangegetRange(a1Notation: string): FRangegetRange(range: IRange): FRangeParameters
row— Optional. The row index of the cell.column— Optional. The column index of the cell.numRows— Optional. The number of rows in the range.numColumns— Optional. The number of columns in the range.a1Notation— Optional. A string representing a range in A1 notation.range— Optional. The range specification.
Returns
A Range object representing the specified cell.
A Range object representing the specified range.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get range for cell at row 0, column 0 (A1)const range = fWorksheet.getRange(0, 0)console.log(range)const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get range for cells A1:C3const range = fWorksheet.getRange(0, 0, 3, 3)console.log(range)const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get range for cells A1:C3const range = fWorksheet.getRange('A1:C3')console.log(range)// Get range for a single cellconst cell = fWorksheet.getRange('B2')console.log(cell)// Get range with sheet nameconst sheetName = fWorksheet.getSheetName()const rangeWithSheet = fWorksheet.getRange(`${sheetName}!A1:C3`)console.log(rangeWithSheet)Package: @univerjs/sheets · Type definitions
FWorksheet.getRowCustomMetadata
Get custom metadata of row
getRowCustomMetadata(index: number): CustomData | undefinedParameters
index— Required. row index
Returns
custom metadata
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')const custom = fWorkSheet.getRowCustomMetadata(0)console.log(custom)Types: CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.getRowDefaultStyle
Get the default style of the worksheet row
getRowDefaultStyle(index: number, keepRaw?: boolean): Nullable<IStyleData> | stringParameters
index— Required. The row indexkeepRaw— Optional. Default:false. If true, return the raw style data maybe the style name or style data, otherwise return the data from row manager
Returns
The default style of the worksheet row name or style data
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get default style for row 0 (1)const rowStyle = fWorksheet.getRowDefaultStyle(0)console.log(rowStyle)// Get raw style data for row 0const rawRowStyle = fWorksheet.getRowDefaultStyle(0, true)console.log(rawRowStyle)Types: Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.getRowHeight
Gets the height in pixels of the given row.
getRowHeight(rowPosition: number): numberParameters
rowPosition— Required. The position of the row to examine. index starts at 0.
Returns
The height in pixels of the given row.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set the value of the cell A1 to 'Hello, Univer!', set the font size to 30 and font weight to boldconst fRange = fWorksheet.getRange('A1')fRange.setValue('Hello, Univer!').setFontSize(30).setFontWeight('bold')// Get the height of the first rowconsole.log(fWorksheet.getRowHeight(0))Package: @univerjs/sheets · Type definitions
FWorksheet.getSelection
Get the current selection of the worksheet.
getSelection(): FSelection | nullReturns
The current selections, or null when no selection data is available.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const selection = fWorksheet.getSelection()console.log(selection)Types: FSelection
Package: @univerjs/sheets · Type definitions
FWorksheet.getSheet
Get the worksheet instance.
getSheet(): WorksheetReturns
The worksheet instance.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const sheet = fWorksheet.getSheet()console.log(sheet)Types: Worksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.getSheetId
Get the worksheet id.
getSheetId(): stringReturns
The id of the worksheet.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const sheetId = fWorksheet.getSheetId()console.log(sheetId)Package: @univerjs/sheets · Type definitions
FWorksheet.getSheetName
Get the worksheet name.
getSheetName(): stringReturns
The name of the worksheet.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const sheetName = fWorksheet.getSheetName()console.log(sheetName)Package: @univerjs/sheets · Type definitions
FWorksheet.getTabColor
Get the tab color of the sheet.
getTabColor(): string | undefinedReturns
The tab color, or undefined when no color is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// get the tab color of the sheetconsole.log(fWorkSheet.getTabColor())Package: @univerjs/sheets · Type definitions
FWorksheet.getWorkbook
Get the workbook instance.
getWorkbook(): WorkbookReturns
The workbook instance.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const workbook = fWorksheet.getWorkbook()console.log(workbook)Types: Workbook
Package: @univerjs/sheets · Type definitions
FWorksheet.getWorksheetPermission
Get the WorksheetPermission instance for managing worksheet-level permissions. This is the new permission API that provides worksheet-specific permission control.
getWorksheetPermission(): FWorksheetPermissionReturns
- The WorksheetPermission instance.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const permission = fWorksheet.getWorksheetPermission()// Set worksheet to read-only modeawait permission.setMode('readOnly')// Check if a specific cell can be editedconst canEdit = permission.canEditCell(0, 0)// Protect multiple ranges at onceconst range1 = fWorksheet.getRange('A1:B10')const range2 = fWorksheet.getRange('D1:E10')await permission.protectRanges([ { ranges: [range1], options: { name: 'Range 1', allowEdit: false } }, { ranges: [range2], options: { name: 'Range 2', allowEdit: false } },])// Subscribe to permission changespermission.permission$.subscribe((snapshot) => { console.log('Worksheet permissions changed:', snapshot)})Types: FWorksheetPermission
Package: @univerjs/sheets · Type definitions
FWorksheet.hasHiddenGridLines
Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
hasHiddenGridLines(): booleanReturns
True if the sheet's gridlines are hidden; otherwise false.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// check if the gridlines are hiddenif (fWorkSheet.hasHiddenGridLines()) { console.log('Gridlines are hidden')}Package: @univerjs/sheets · Type definitions
FWorksheet.hideColumn
Hides the column or columns in the given range.
hideColumn(column: FRange): FWorksheetParameters
column— Required. The column range to hide
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Hide columns C, D, Econst column1 = fWorksheet.getRange('C:E')fWorksheet.hideColumn(column1)// Hide column Aconst column2 = fWorksheet.getRange('A:A')fWorksheet.hideColumn(column2)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.hideColumns
Hides one or more consecutive columns starting at the given index. Use 0-index for this method
hideColumns(columnIndex: number, numColumn?: number): FWorksheetParameters
columnIndex— Required. The starting index of the columns to hidenumColumn— Optional. Default:1. The number of columns to hide
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Hide columns C, D, EfWorksheet.hideColumns(2, 3)// Hide column AfWorksheet.hideColumns(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.hideRow
Hides the rows in the given range.
hideRow(row: FRange): FWorksheetParameters
row— Required. The row range to hide.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Hide 3 rows starting from row index 1 (rows 2-4)const row1 = fWorksheet.getRange('2:4')fWorksheet.hideRow(row1)// Hide single row at index 0 (first row)const row2 = fWorksheet.getRange('1:1')fWorksheet.hideRow(row2)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.hideRows
Hides one or more consecutive rows starting at the given index. Use 0-index for this method
hideRows(rowIndex: number, numRow?: number): FWorksheetParameters
rowIndex— Required. The starting index of the rows to hidenumRow— Optional. Default:1. The number of rows to hide
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Hide 3 rows starting from row index 1 (rows 2-4)fWorksheet.hideRows(1, 3)// Hide single row at index 0 (first row)fWorksheet.hideRows(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.hideSheet
Hides this sheet. Has no effect if the sheet is already hidden. If this method is called on the only visible sheet, it throws an exception.
hideSheet(): FWorksheetReturns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// hide the active sheetfWorkSheet.hideSheet()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertColumnAfter
Inserts a column after the given column position.
insertColumnAfter(afterPosition: number): FWorksheetParameters
afterPosition— Required. The column after which the new column should be added, starting at 0 for the first column
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a column after column CfWorksheet.insertColumnAfter(2)// Insert a column after column AfWorksheet.insertColumnAfter(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertColumnBefore
Inserts a column before the given column position.
insertColumnBefore(beforePosition: number): FWorksheetParameters
beforePosition— Required. The column before which the new column should be added, starting at 0 for the first column
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a column before column CfWorksheet.insertColumnBefore(2)// Insert a column before column AfWorksheet.insertColumnBefore(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertColumns
Inserts one or more consecutive blank columns in a sheet starting at the specified location.
insertColumns(columnIndex: number, numColumns?: number): FWorksheetParameters
columnIndex— Required. The index indicating where to insert a column, starting at 0 for the first columnnumColumns— Optional. Default:1. The number of columns to insert
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 columns before column CfWorksheet.insertColumns(2, 3)// Insert 1 column before column AfWorksheet.insertColumns(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertColumnsAfter
Inserts a given number of columns after the given column position.
insertColumnsAfter(afterPosition: number, howMany: number): FWorksheetParameters
afterPosition— Required. The column after which the new columns should be added, starting at 0 for the first columnhowMany— Required. The number of columns to insert
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 columns after column CfWorksheet.insertColumnsAfter(2, 3)// Insert 1 column after column AfWorksheet.insertColumnsAfter(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertColumnsBefore
Inserts a number of columns before the given column position.
insertColumnsBefore(beforePosition: number, howMany: number): FWorksheetParameters
beforePosition— Required. The column before which the new columns should be added, starting at 0 for the first columnhowMany— Required. The number of columns to insert
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 columns before column CfWorksheet.insertColumnsBefore(2, 3)// Insert 1 column before column AfWorksheet.insertColumnsBefore(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertDefinedName
Insert a defined name for worksheet.
insertDefinedName(name: string, formulaOrRefString: string): voidParameters
name— Required. The name of the defined name to insertformulaOrRefString— Required. The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
Examples
// The code below inserts a defined nameconst fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.insertDefinedName('MyDefinedName', 'Sheet1!$A$1')Package: @univerjs/sheets · Type definitions
FWorksheet.insertRowAfter
Inserts a row after the given row position.
insertRowAfter(afterPosition: number): FWorksheetParameters
afterPosition— Required. The existing row after which the new row should be added. The index is zero-based and must be between 0 andgetMaxRows() - 1.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a row after the third rowfWorksheet.insertRowAfter(2)// Insert a row after the first rowfWorksheet.insertRowAfter(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertRowBefore
Inserts a row before the given row position.
insertRowBefore(beforePosition: number): FWorksheetParameters
beforePosition— Required. The existing row before which the new row should be added. The index is zero-based and must be between 0 andgetMaxRows() - 1.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert a row before the third rowfWorksheet.insertRowBefore(2)// Insert a row before the first rowfWorksheet.insertRowBefore(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertRows
Inserts one or more consecutive blank rows in a sheet starting at the specified location.
insertRows(rowIndex: number, numRows?: number): FWorksheetParameters
rowIndex— Required. The existing row before which rows are inserted. The index is zero-based and must be between 0 andgetMaxRows() - 1.numRows— Optional. Default:1. The positive number of rows to insert.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 rows before the third rowfWorksheet.insertRows(2, 3)// Insert 1 row before the first rowfWorksheet.insertRows(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertRowsAfter
Inserts a number of rows after the given row position.
insertRowsAfter(afterPosition: number, howMany: number): FWorksheetParameters
afterPosition— Required. The existing row after which the new rows should be added. The index is zero-based and must be between 0 andgetMaxRows() - 1.howMany— Required. The positive number of rows to insert.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 rows after the third rowfWorksheet.insertRowsAfter(2, 3)// Insert 1 row after the first rowfWorksheet.insertRowsAfter(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.insertRowsBefore
Inserts a number of rows before the given row position.
insertRowsBefore(beforePosition: number, howMany: number): FWorksheetParameters
beforePosition— Required. The existing row before which the new rows should be added. The index is zero-based and must be between 0 andgetMaxRows() - 1.howMany— Required. The positive number of rows to insert.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Insert 3 rows before the third rowfWorksheet.insertRowsBefore(2, 3)// Insert 1 row before the first rowfWorksheet.insertRowsBefore(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.isSheetHidden
Returns true for both HIDDEN and VERY_HIDDEN sheets.
isSheetHidden(): booleanReturns
True if the sheet is hidden; otherwise, false.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheets = fWorkbook.getSheets()// check if the last sheet is hiddenconsole.log(fWorkSheets[fWorkSheets.length - 1].isSheetHidden())Package: @univerjs/sheets · Type definitions
FWorksheet.moveColumns
Moves the columns selected by the given range to the position indicated by the destinationIndex. The columnSpec itself does not have to exactly represent an entire column or group of columns to move—it selects all columns that the range spans.
moveColumns(columnSpec: FRange, destinationIndex: number): FWorksheetParameters
columnSpec— Required. A range spanning the columns that should be moveddestinationIndex— Required. The index that the columns should be moved to. Note that this index is based on the coordinates before the columns are moved. Existing data is shifted right to make room for the moved columns while the source columns are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Move columns C, D, E to column index 2 (columns B, C, D)const columnSpec1 = fWorksheet.getRange('C:E')fWorksheet.moveColumns(columnSpec1, 1)// Move column F to column index 0 (column A)const columnSpec2 = fWorksheet.getRange('F:F')fWorksheet.moveColumns(columnSpec2, 0)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.moveRows
Moves the rows selected by the given range to the position indicated by the destinationIndex. The rowSpec itself does not have to exactly represent an entire row or group of rows to move—it selects all rows that the range spans.
moveRows(rowSpec: FRange, destinationIndex: number): FWorksheetParameters
rowSpec— Required. A range spanning the rows that should be moved.destinationIndex— Required. The index that the rows should be moved to. Note that this index is based on the coordinates before the rows are moved. Existing data is shifted down to make room for the moved rows while the source rows are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Move 3 rows at row index 2 (rows 3-5) to row index 0const rowSpec1 = fWorksheet.getRange('3:5')fWorksheet.moveRows(rowSpec1, 0)// Move 1 row at row index 0 (first row) to row index 2const rowSpec2 = fWorksheet.getRange('1:1')fWorksheet.moveRows(rowSpec2, 2)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.setActiveRange
Sets the active selection region for this sheet.
setActiveRange(range: FRange): FWorksheetParameters
range— Required. The range to set as the active selection
Returns
This sheet, for chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setActiveRange(fWorkSheet.getRange('A10:B10'))Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.setActiveSelection
Sets the active selection region for this sheet.
setActiveSelection: (range: FRange) => FWorksheetReturns
This sheet, for chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setActiveSelection(fWorkSheet.getRange('A10:B10'))Types: FRange · FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnCount
Sets the number of columns in the worksheet.
setColumnCount(columnCount: number): FWorksheetParameters
columnCount— Required. The number of columns to set.
Returns
Returns the current worksheet instance for method chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Set the number of columns in the worksheet to 10fWorkSheet.setColumnCount(10)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnCustom
Set custom properties for given columns.
setColumnCustom(custom: IObjectArrayPrimitiveType<CustomData>): FWorksheetParameters
custom— Required. The custom properties to set
Returns
This worksheet instance for chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setColumnCustom({ 0: { key: 'value' } })Types: FWorksheet · IObjectArrayPrimitiveType · CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnCustomMetadata
Set custom metadata of column
setColumnCustomMetadata(index: number, custom: CustomData | undefined): FWorksheetParameters
index— Required. column indexcustom— Required. custom metadata
Returns
Current worksheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setColumnCustomMetadata(0, { key: 'value' })Types: FWorksheet · CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnDefaultStyle
Set the default style of the worksheet column
setColumnDefaultStyle(index: number, style: string | Nullable<IStyleData>): FWorksheetParameters
index— Required. The zero-based column indexstyle— Required. The style name or style data
Returns
This sheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setColumnDefaultStyle(0, 'default')// or// fWorksheet.setColumnDefaultStyle(0, {fs: 12, ff: 'Arial'});Types: FWorksheet · Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnWidth
Sets the width of the given column in pixels.
setColumnWidth(columnPosition: number, width: number): FWorksheetParameters
columnPosition— Required. The position of the given column to setwidth— Required. The width in pixels to set it to
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set width of column B to 100 pixelsfWorksheet.setColumnWidth(1, 100)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setColumnWidths
Sets the width of the given columns in pixels.
setColumnWidths(startColumn: number, numColumn: number, width: number): FWorksheetParameters
startColumn— Required. The starting column position to changenumColumn— Required. The number of columns to changewidth— Required. The width in pixels to set it to
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set width of columns B-D (index 1-3) to 100 pixelsfWorksheet.setColumnWidths(1, 3, 100)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setCustomMetadata
Set custom metadata of worksheet
setCustomMetadata(custom: CustomData | undefined): FWorksheetParameters
custom— Required. custom metadata
Returns
Current worksheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setCustomMetadata({ key: 'value' })Types: FWorksheet · CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.setDefaultStyle
Set the default style of the worksheet
setDefaultStyle(style: string | Nullable<IStyleData>): FWorksheetParameters
style— Required. A style ID or style object, ornullto clear the default style.
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setDefaultStyle('default')// or// fWorksheet.setDefaultStyle({fs: 12, ff: 'Arial'});Types: FWorksheet · Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.setFreeze
Sets the frozen state of the current sheet.
setFreeze(freeze: IFreeze): FWorksheetParameters
freeze— Required. the scrolling viewport start range and count of freezed rows and columns. that means if you want to freeze the first 3 rows and 2 columns, you should set freeze as { startRow: 3, startColumn: 2, xSplit: 2, ySplit: 3 }
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Freeze first 3 rows and 2 columnsfWorksheet.setFreeze({ startRow: 3, startColumn: 2, xSplit: 2, ySplit: 3,})Types: FWorksheet · IFreeze
Package: @univerjs/sheets · Type definitions
FWorksheet.setFrozenColumns
Set the number of frozen columns.
setFrozenColumns(columns: number): FWorksheetsetFrozenColumns(startColumn: number, endColumn: number): FWorksheetParameters
columns— Optional. The number of columns to freeze. To unfreeze all columns, set this value to 0.startColumn— Optional. The start column of the range to freezeendColumn— Optional. The end column of the range to freeze
Returns
This FWorksheet instance.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// freeze the first 3 columns.fWorkSheet.setFrozenColumns(3)const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// freeze the column B and C, and column A will be invisible.fWorkSheet.setFrozenColumns(1, 2)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setFrozenRows
Set the number of frozen rows.
setFrozenRows(rows: number): FWorksheetsetFrozenRows(startRow: number, endRow: number): FWorksheetParameters
rows— Optional. The number of rows to freeze. To unfreeze all rows, set this value to 0.startRow— Optional. The start row of the range to freezeendRow— Optional. The end row of the range to freeze
Returns
This FWorksheet instance.
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// freeze the first 3 rows.fWorkSheet.setFrozenRows(3)const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// freeze the second and third rows, and the first row will be invisible.fWorkSheet.setFrozenRows(1, 2)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setGridLinesColor
Set the color of the gridlines in the sheet.
setGridLinesColor(color: string | undefined): FWorksheetParameters
color— Required. The color to set for the gridlines.Undefined or null to reset to the default color.
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// set the gridlines color to redfWorkSheet.setGridLinesColor('#ff0000')Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setHiddenGridlines
Hides or reveals the sheet gridlines.
setHiddenGridlines(hidden: boolean): FWorksheetParameters
hidden— Required. Iftrue, hide gridlines in this sheet; otherwise show the gridlines.
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// hide the gridlinesfWorkSheet.setHiddenGridlines(true)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setHiddenState
Changes the persisted hiding state through an undoable command. VERY_HIDDEN removes the sheet from Unhide UI; showSheet() can reveal it through the API. The last visible sheet cannot be hidden. Existing isSheetHidden() stays a boolean predicate.
setHiddenState(hidden: WorksheetHiddenState): FWorksheetParameters
hidden— Required.
Examples
fWorksheet.setHiddenState(univerAPI.Enum.WorksheetHiddenState.VERY_HIDDEN)
Types: FWorksheet · WorksheetHiddenState
Package: @univerjs/sheets · Type definitions
FWorksheet.setName
Sets the sheet name.
setName(name: string): FWorksheetParameters
name— Required. The new name for the sheet.
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// set the sheet name to 'Sheet1'fWorkSheet.setName('NewSheet1')Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setRangesAutoHeight
Sets the height of the given ranges to auto.
setRangesAutoHeight(ranges: IRange[]): FWorksheetParameters
ranges— Required. The ranges to change
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const ranges = [ { startRow: 1, endRow: 10, startColumn: 0, endColumn: 10 }, { startRow: 11, endRow: 20, startColumn: 0, endColumn: 10 },]fWorksheet.setRangesAutoHeight(ranges)Types: FWorksheet · IRange
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowAutoHeight
Sets the height of the given rows to auto.
setRowAutoHeight(startRow: number, numRows: number): FWorksheetParameters
startRow— Required. The starting row position to changenumRows— Required. The number of rows to change
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setRowAutoHeight(1, 10)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowCount
Sets the number of rows in the worksheet.
setRowCount(rowCount: number): FWorksheetParameters
rowCount— Required. The number of rows to set.
Returns
Returns the current worksheet instance for method chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// Set the number of rows in the worksheet to 40fWorkSheet.setRowCount(40)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowCustom
Set custom properties for given rows.
setRowCustom(custom: IObjectArrayPrimitiveType<CustomData>): FWorksheetParameters
custom— Required. The custom properties to set
Returns
This worksheet instance for chaining
Examples
const fWorkSheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setRowCustom({ 0: { key: 'value' } })Types: FWorksheet · IObjectArrayPrimitiveType · CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowCustomMetadata
Set custom metadata of row
setRowCustomMetadata(index: number, custom: CustomData | undefined): FWorksheetParameters
index— Required. row indexcustom— Required. custom metadata
Returns
Current worksheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')fWorkSheet.setRowCustomMetadata(0, { key: 'value' })Types: FWorksheet · CustomData
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowDefaultStyle
Set the default style of the worksheet row
setRowDefaultStyle(index: number, style: string | Nullable<IStyleData>): FWorksheetParameters
index— Required. The zero-based row indexstyle— Required. The style name or style data
Returns
This sheet, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setRowDefaultStyle(0, 'default')// or// fWorksheet.setRowDefaultStyle(0, {fs: 12, ff: 'Arial'});Types: FWorksheet · Nullable · IStyleData
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowHeight
Sets the row height of the given row in pixels. By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
setRowHeight(rowPosition: number, height: number): FWorksheetParameters
rowPosition— Required. The row position to change.height— Required. The height in pixels to set it to.
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set the height of the second row to 30 pixelsfWorksheet.setRowHeight(1, 30)// Set the height of the first row to 20 pixelsfWorksheet.setRowHeight(0, 20)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowHeights
Sets the height of the given rows in pixels. By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
setRowHeights(startRow: number, numRows: number, height: number): FWorksheetParameters
startRow— Required. The starting row position to changenumRows— Required. The number of rows to changeheight— Required. The height in pixels to set it to
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setRowHeights(1, 10, 30)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setRowHeightsForced
Sets the height of the given rows in pixels. By default, rows grow to fit cell contents. When you use setRowHeightsForced, rows are forced to the specified height even if the cell contents are taller than the row height.
setRowHeightsForced(startRow: number, numRows: number, height: number): FWorksheetParameters
startRow— Required. The starting row position to changenumRows— Required. The number of rows to changeheight— Required. The height in pixels to set it to
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setRowHeightsForced(1, 10, 30)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.setTabColor
Sets the sheet tab color.
setTabColor(color: string): FWorksheetParameters
color— Required. A color in CSS notation, such as '#ffffff' or 'white'.
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheet = fWorkbook.getSheetByName('Sheet1')if (!fWorkSheet) throw new Error('fWorkSheet is not available')// set the tab color to redfWorkSheet.setTabColor('#ff0000')Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.showColumns
Show one or more consecutive columns starting at the given index. Use 0-index for this method
showColumns(columnIndex: number, numColumns?: number): FWorksheetParameters
columnIndex— Required. The starting index of the columns to unhidenumColumns— Optional. Default:1. The number of columns to unhide
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Unhide columns C, D, EfWorksheet.showColumns(2, 3)// Unhide column AfWorksheet.showColumns(0, 1)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.showRows
Unhides one or more consecutive rows starting at the given zero-based index.
showRows(rowIndex: number, numRows?: number): FWorksheetParameters
rowIndex— Required. The starting index of the rowsnumRows— Optional. Default:1. The number of rows
Returns
This worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Show 3 rows starting from row index 1 (rows 2-4)fWorksheet.showRows(1, 3)// Show single row at index 0 (first row)fWorksheet.showRows(0)Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.showSheet
Shows this sheet. Has no effect if the sheet is already visible.
showSheet(): FWorksheetReturns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorkSheets = fWorkbook.getSheets()// show the last sheetfWorkSheets[fWorkSheets.length - 1].showSheet()Types: FWorksheet
Package: @univerjs/sheets · Type definitions
FWorksheet.unhideColumn
Show the column in the given range.
unhideColumn(column: FRange): FWorksheetParameters
column— Required. The range to unhide, if hidden
Returns
This sheet, for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Unhide columns C, D, Econst column1 = fWorksheet.getRange('C:E')fWorksheet.unhideColumn(column1)// Unhide column Aconst column2 = fWorksheet.getRange('A:A')fWorksheet.unhideColumn(column2)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
FWorksheet.unhideRow
Make the row in the given range visible.
unhideRow(row: FRange): FWorksheetParameters
row— Required. The range to unhide, if hidden.
Returns
This sheet, for chaining.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Unhide 3 rows starting from row index 1 (rows 2-4)const row1 = fWorksheet.getRange('2:4')fWorksheet.unhideRow(row1)// Unhide single row at index 0 (first row)const row2 = fWorksheet.getRange('1:1')fWorksheet.unhideRow(row2)Types: FWorksheet · FRange
Package: @univerjs/sheets · Type definitions
@univerjs/sheets-conditional-formatting
FWorksheet.addConditionalFormattingRule
Add a new conditional format
addConditionalFormattingRule(rule: IConditionFormattingRule): FWorksheetParameters
rule— Required. The conditional formatting rule to add
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a conditional formatting rule that sets the cell format to italic, red background, and green font color when the cell is not empty.const fRange = fWorksheet.getRange('A1:T100')const rule = fWorksheet .newConditionalFormattingRule() .whenCellNotEmpty() .setRanges([fRange.getRange()]) .setItalic(true) .setBackground('red') .setFontColor('green') .build()fWorksheet.addConditionalFormattingRule(rule)Types: FWorksheet · IConditionFormattingRule
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.clearConditionalFormatRules
Removes all conditional format rules from the sheet.
clearConditionalFormatRules(): FWorksheetReturns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.clearConditionalFormatRules()console.log(fWorksheet.getConditionalFormattingRules()) // []Types: FWorksheet
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.deleteConditionalFormattingRule
Delete conditional format according to cfId
deleteConditionalFormattingRule(cfId: string): FWorksheetParameters
cfId— Required. The conditional formatting rule id to delete
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = fWorksheet.getConditionalFormattingRules()// Delete the first rulefWorksheet.deleteConditionalFormattingRule(rules[0]?.cfId)Types: FWorksheet
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.getConditionalFormattingRules
Gets all the conditional formatting for the current sheet
getConditionalFormattingRules(): IConditionFormattingRule[]Returns
conditional formatting rules for the current sheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = fWorksheet.getConditionalFormattingRules()console.log(rules)Types: IConditionFormattingRule
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.moveConditionalFormattingRule
Modify the priority of the conditional format
moveConditionalFormattingRule(cfId: string, toCfId: string, type?: IAnchor['type']): FWorksheetParameters
cfId— Required. The conditional formatting rule id to movetoCfId— Required. Target ruletype— Optional. Default:'after'. After the default move to the destination rule, if type = before moves to the front, the default value is after
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = fWorksheet.getConditionalFormattingRules()// Move the third rule before the first ruleconst rule = rules[2]const targetRule = rules[0]fWorksheet.moveConditionalFormattingRule(rule?.cfId, targetRule?.cfId, 'before')Types: FWorksheet · IAnchor
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.newConditionalFormattingRule
Creates a constructor for conditional formatting
newConditionalFormattingRule(): FConditionalFormattingBuilderReturns
The conditional formatting builder
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a conditional formatting rule that sets the cell format to italic, red background, and green font color when the cell is not empty.const fRange = fWorksheet.getRange('A1:T100')const rule = fWorksheet .newConditionalFormattingRule() .whenCellNotEmpty() .setRanges([fRange.getRange()]) .setItalic(true) .setBackground('red') .setFontColor('green') .build()fWorksheet.addConditionalFormattingRule(rule)Types: FConditionalFormattingBuilder
Package: @univerjs/sheets-conditional-formatting · Type definitions
FWorksheet.setConditionalFormattingRule
Set the conditional format according to cfId
setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FWorksheetParameters
cfId— Required. The conditional formatting rule id to setrule— Required. The conditional formatting rule to set
Returns
Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a conditional formatting rule that sets the cell format to italic, red background, and green font color when the cell is not empty.const fRange = fWorksheet.getRange('A1:T100')const rule = fWorksheet .newConditionalFormattingRule() .whenCellNotEmpty() .setRanges([fRange.getRange()]) .setItalic(true) .setBackground('red') .setFontColor('green') .build()fWorksheet.addConditionalFormattingRule(rule)// Modify the first rule to apply to a new rangeconst rules = fWorksheet.getConditionalFormattingRules()const newRuleRange = fWorksheet.getRange('A1:D10')fWorksheet.setConditionalFormattingRule(rules[0]?.cfId, { ...rules[0], ranges: [newRuleRange.getRange()],})Types: FWorksheet · IConditionFormattingRule
Package: @univerjs/sheets-conditional-formatting · Type definitions
@univerjs/sheets-data-validation
FWorksheet.getAllDataValidationErrorAsync
Get all data validation errors for current worksheet.
getAllDataValidationErrorAsync(): Promise<IDataValidationError[]>Returns
A promise that resolves to an array of validation errors.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const errors = await fWorksheet.getAllDataValidationErrorAsync()console.log(errors)Types: IDataValidationError · Promise
Package: @univerjs/sheets-data-validation · Type definitions
FWorksheet.getDataValidation
get data validation rule by rule id
getDataValidation(ruleId: string): Nullable<FDataValidation>Parameters
ruleId— Required. the rule id
Returns
data validation rule
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = fWorksheet.getDataValidations()console.log(fWorksheet.getDataValidation(rules[0]?.rule.uid))Types: FDataValidation · Nullable
Package: @univerjs/sheets-data-validation · Type definitions
FWorksheet.getDataValidations
Get all data validation rules in current sheet.
getDataValidations(): FDataValidation[]Returns
All data validation rules
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = fWorksheet.getDataValidations()console.log(rules)Types: FDataValidation
Package: @univerjs/sheets-data-validation · Type definitions
FWorksheet.getValidatorStatusAsync
Get data validation validator status for current sheet.
getValidatorStatusAsync(): Promise<ObjectMatrix<Nullable<DataValidationStatus>>>Returns
matrix of validator status
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const status = await fWorksheet.getValidatorStatusAsync()console.log(status)Types: ObjectMatrix · Nullable · DataValidationStatus · Promise
Package: @univerjs/sheets-data-validation · Type definitions
@univerjs/sheets-drawing
FWorksheet.deleteBackgroundImage
Deletes the image tiled behind the worksheet grid.
deleteBackgroundImage(): thisReturns
The current worksheet instance for chaining.
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.deleteImages
Delete images from the sheet
deleteImages(sheetImages: FOverGridImage[]): FWorksheetParameters
sheetImages— Required. The images to delete
Returns
The FWorksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const image = fWorksheet.getImages()[0]// Delete the first image of the sheetfWorksheet.deleteImages([image])Types: FWorksheet · FOverGridImage
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getActiveImages
Get the current selected images.
getActiveImages(): FOverGridImage[]Returns
The FOverGridImage instances
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const images = fWorksheet.getActiveImages()images.forEach((image) => { console.log(image, image.getId())})Types: FOverGridImage
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getBackgroundImage
Returns the image tiled behind the worksheet grid.
getBackgroundImage(): Nullable<IWorksheetBackgroundImage>Returns
The worksheet background image, or null when absent.
Types: IWorksheetBackgroundImage · Nullable
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getDrawingGroupChildren
Get children of a drawing group on the current sheet.
getDrawingGroupChildren(groupId: string, recursive?: boolean): ISheetDrawing[]Parameters
groupId— Required. The group drawing id.recursive— Optional. Default:false. Whether to return all descendants.
Returns
The child drawings.
Examples
// Get the direct children of a drawing group.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const image1 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(1) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()const image2 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(3) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()fWorksheet.insertImages([image1, image2])const groupId = fWorksheet.groupDrawings([image1.drawingId, image2.drawingId])if (groupId) { const children = fWorksheet.getDrawingGroupChildren(groupId) console.log(children.map((drawing) => drawing.drawingId))}Types: ISheetDrawing
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getDrawingLayout
Get the Sheet host layout in model coordinates.
This API is available in Node/headless and does not include viewport, scroll, zoom, frozen-pane clipping, or screen coordinates.
getDrawingLayout(): ISheetDrawingLayoutReturns
Grid, data, and ordered Drawing bounds.
Examples
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const layout = sheet.getDrawingLayout()console.log(layout.gridBounds, layout.dataBounds)for (const drawing of layout.drawings) { console.log(drawing.drawingId, drawing.bounds)}Types: ISheetDrawingLayout
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getDrawingParentGroup
Get the parent group of a drawing on the current sheet.
getDrawingParentGroup(drawingId: string): ISheetDrawing | nullParameters
drawingId— Required. The child drawing id.
Returns
The parent group drawing, or null if the drawing is not grouped.
Examples
// Get the parent group of a drawing.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const image1 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(1) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()const image2 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(3) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()fWorksheet.insertImages([image1, image2])fWorksheet.groupDrawings([image1.drawingId, image2.drawingId])const parentGroup = fWorksheet.getDrawingParentGroup(image1.drawingId)console.log(parentGroup?.drawingId)Types: ISheetDrawing
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getDrawingPlacement
Get the placement of any drawing on this sheet.
Image, Shape, Chart, and Group use the same placement contract.
getDrawingPlacement(drawingId: string): ISheetDrawingPlacement | nullParameters
drawingId— Required. Drawing id.
Returns
The placement, or null when the drawing does not exist.
Examples
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const placement = sheet.getDrawingPlacement('drawing-id')if (placement?.kind === univerAPI.Enum.SheetDrawingAnchorType.Both) { console.log(placement.from, placement.to)}Types: ISheetDrawingPlacement
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getImageById
Get image by drawing id
getImageById(id: string): FOverGridImage | nullParameters
id— Required. The drawing id of the image
Returns
The FOverGridImage instance
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const image = fWorksheet.getImageById('xxxx')console.log(image)Types: FOverGridImage
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.getImages
Get all images of the sheet.
getImages(): FOverGridImage[]Returns
The FOverGridImage instances
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const images = fWorksheet.getImages()images.forEach((image) => { console.log(image, image.getId())})Types: FOverGridImage
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.groupDrawings
Group drawings on the current sheet.
groupDrawings(drawingIds: string[], groupId?: string): string | nullParameters
drawingIds— Required. The drawing ids to group. At least two drawings are required.groupId— Optional. Default:generateRandomId(10). Optional group drawing id. If omitted, a new id will be generated.
Returns
The group id if the operation succeeds, otherwise null.
Examples
// Group two over-grid images on the active sheet.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const image1 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(1) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()const image2 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(3) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()fWorksheet.insertImages([image1, image2])const groupId = fWorksheet.groupDrawings([image1.drawingId, image2.drawingId])console.log(groupId)Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.insertImage
Insert an image to the sheet
insertImage(url: IFBlobSource | string, column?: number, row?: number, offsetX?: number, offsetY?: number): Promise<boolean>Parameters
url— Required. The image urlcolumn— Optional. The column index to insert the imagerow— Optional. The row index to insert the imageoffsetX— Optional. The column offset, pixel unitoffsetY— Optional. The row offset, pixel unit
Returns
true if the image is inserted successfully
True if the image is inserted successfully
Examples
// Insert an image to the sheet, default position is A1const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const result = await fWorksheet.insertImage( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4',)console.log(result)// Insert an image to the sheet, position is F6const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const result = await fWorksheet.insertImage( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', 5, 5,)console.log(result)// Insert an image to the sheet, position is F6, offset is 10pxconst fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const result = await fWorksheet.insertImage( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', 5, 5, 10, 10,)console.log(result)Types: Promise · IFBlobSource
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.insertImages
Insert images to the sheet
insertImages(sheetImages: ISheetImage[]): FWorksheetParameters
sheetImages— Required. The images to insert
Returns
The FWorksheet instance for chaining
Examples
// create a new image builder and set image source.// then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 500px, height is 300pxconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const image = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(5) .setRow(5) .setWidth(500) .setHeight(300) .buildAsync()fWorksheet.insertImages([image])// update the image width to 100px and height to 50pxsetTimeout(async () => { const imageBuilder = fWorksheet.getImageById(image.drawingId).toBuilder() const newImage = await imageBuilder.setWidth(100).setHeight(50).buildAsync() fWorksheet.updateImages([newImage])}, 4000)Types: FWorksheet · ISheetImage
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.isDrawingGrouped
Returns whether a drawing is inside a group on the current sheet.
isDrawingGrouped(drawingId: string): booleanParameters
drawingId— Required. The drawing id.
Returns
true if the drawing has a parent group.
Examples
// Check whether a drawing is inside a group.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const image1 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(1) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()const image2 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(3) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()fWorksheet.insertImages([image1, image2])fWorksheet.groupDrawings([image1.drawingId, image2.drawingId])const isGrouped = fWorksheet.isDrawingGrouped(image1.drawingId)console.log(isGrouped)Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.newOverGridImage
Create a new over grid image builder.
newOverGridImage(): FOverGridImageBuilderReturns
The FOverGridImageBuilder instance
Examples
// create a new image builder and set image source.// then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 500px, height is 300pxconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const image = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(5) .setRow(5) .setWidth(500) .setHeight(300) .buildAsync()fWorksheet.insertImages([image])Types: FOverGridImageBuilder
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.resolveDrawingPlacement
Resolve exact markers or model-space bounds to a normalized Placement.
Bounds inference is usually preferable when positioning from an existing
transform. Exact markers are useful when the caller must preserve a
user-selected cell and offset. Position maps to OOXML OneCell,
Both maps to TwoCell, and None maps to Absolute.
resolveDrawingPlacement(placement: ISheetDrawingPlacementInput): ISheetDrawingPlacementParameters
placement— Required. Exact markers or bounds with an explicit anchor type.
Returns
The normalized Placement.
Examples
Infer Position and Both placements from bounds in Node/headless
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const positionPlacement = sheet.resolveDrawingPlacement({ kind: univerAPI.Enum.SheetDrawingAnchorType.Position, bounds: { left: 120, top: 80, width: 320, height: 160 },})const bothPlacement = sheet.resolveDrawingPlacement({ kind: univerAPI.Enum.SheetDrawingAnchorType.Both, bounds: { left: 120, top: 80, width: 320, height: 160 },})console.log(positionPlacement.from)console.log(bothPlacement.from, bothPlacement.to)Types: ISheetDrawingPlacement · ISheetDrawingPlacementInput
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.setBackgroundImage
Sets the image tiled behind the worksheet grid. Worksheet background images are not printed.
setBackgroundImage(source: string, imageSourceType?: ImageSourceType): thisParameters
source— Required. Image source.imageSourceType— Optional. Default:ImageSourceType.URL. Image source type.
Returns
The current worksheet instance for chaining.
Types: ImageSourceType
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.setDrawingPlacement
Set the placement of any drawing on this sheet through the drawing command.
setDrawingPlacement(drawingId: string, placement: ISheetDrawingPlacementInput): booleanParameters
drawingId— Required. Drawing id.placement— Required. Exact markers or model-space bounds with an explicit anchor type.
Returns
true when the command succeeds.
Examples
OneCell: move with cells, keep pixel size
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const drawingId = sheet.getImages()[0]?.getId()if (!drawingId) throw new Error('No drawing found.')const changed = sheet.setDrawingPlacement(drawingId, { kind: univerAPI.Enum.SheetDrawingAnchorType.Position, from: { row: 2, column: 2, rowOffset: 8, columnOffset: 8 }, width: 240, height: 120,})console.log(changed)TwoCell: move and resize with both cell markers
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const drawingId = sheet.getImages()[0]?.getId()if (!drawingId) throw new Error('No drawing found.')sheet.setDrawingPlacement(drawingId, { kind: univerAPI.Enum.SheetDrawingAnchorType.Both, from: { row: 2, column: 2, rowOffset: 8, columnOffset: 8 }, to: { row: 8, column: 6, rowOffset: 0, columnOffset: 0 },})Absolute: do not move or resize after row or column changes
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()const drawingId = sheet.getImages()[0]?.getId()if (!drawingId) throw new Error('No drawing found.')sheet.setDrawingPlacement(drawingId, { kind: univerAPI.Enum.SheetDrawingAnchorType.None, left: 640, top: 96, width: 240, height: 120,})Types: ISheetDrawingPlacementInput
Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.ungroupDrawings
Ungroup drawing groups on the current sheet.
ungroupDrawings(groupIds: string[]): booleanParameters
groupIds— Required. The group drawing ids to ungroup.
Returns
true if the operation succeeds, otherwise false.
Examples
// Group two images, then ungroup the generated group.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const image1 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(1) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()const image2 = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(3) .setRow(1) .setWidth(100) .setHeight(100) .buildAsync()fWorksheet.insertImages([image1, image2])const groupId = fWorksheet.groupDrawings([image1.drawingId, image2.drawingId])if (groupId) { const result = fWorksheet.ungroupDrawings([groupId]) console.log(result)}Package: @univerjs/sheets-drawing · Type definitions
FWorksheet.updateImages
Update images to the sheet
updateImages(sheetImages: ISheetImage[]): FWorksheetParameters
sheetImages— Required. The images to update
Returns
The FWorksheet instance for chaining
Examples
// create a new image builder and set image source.// then build `ISheetImage` and insert it into the sheet, position is start from F6 cell, width is 500px, height is 300pxconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const image = await fWorksheet .newOverGridImage() .setSource( 'https://avatars.githubusercontent.com/u/61444807?s=48&v=4', univerAPI.Enum.ImageSourceType.URL, ) .setColumn(5) .setRow(5) .setWidth(500) .setHeight(300) .buildAsync()fWorksheet.insertImages([image])// update the image width to 100px and height to 50px after 4 secondssetTimeout(async () => { const imageBuilder = fWorksheet.getImageById(image.drawingId).toBuilder() const newImage = await imageBuilder.setWidth(100).setHeight(50).buildAsync() fWorksheet.updateImages([newImage])}, 4000)Types: FWorksheet · ISheetImage
Package: @univerjs/sheets-drawing · Type definitions
@univerjs/sheets-drawing-ui
FWorksheet.addFloatDomToColumnHeader
Add dom at column header, And FloatDOM is registerComponent(BuiltInUIPart.CONTENT)
addFloatDomToColumnHeader(column: number, layer: IFICanvasFloatDom, domLayout: IDOMAnchor, id?: string): Nullable<{ id: string; dispose: () => void; }>Parameters
column— Required. The column index to add the float dom.layer— Required. The float dom layer configuration.domLayout— Required.id— Optional. The float dom id, if not given will be auto generated
Returns
float dom id and dispose function
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Register a float button componentconst FloatButton = () => { const divStyle = { width: '100px', height: '30px', backgroundColor: '#fff', border: '1px solid #ccc', boxSizing: 'border-box' as const, display: 'flex', justifyContent: 'center', alignItems: 'center', textAlign: 'center' as const, cursor: 'pointer', } const clickHandler = () => { console.warn('click') } return ( <div style={divStyle} onClick={clickHandler}> FloatButton </div> )}univerAPI.registerComponent('FloatButton', FloatButton)// Add the float button to the column D header, position is right align, width is 100px, height is 30px, margin is 0const disposable = fWorksheet.addFloatDomToColumnHeader( 3, { componentKey: 'FloatButton', allowTransform: false, }, { width: 100, height: 30, marginX: 0, marginY: 0, horizonOffsetAlign: 'right', }, 'myFloatButton',)console.log(disposable?.id) // The id of the floating DOM// Remove the float button after 2 secondssetTimeout(() => { disposable?.dispose()}, 2000)Types: Nullable · IFICanvasFloatDom · IDOMAnchor
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.addFloatDomToPosition
Add a float dom to position.
addFloatDomToPosition(layer: IFICanvasFloatDom, id?: string): Nullable<{ id: string; dispose: () => void; }>Parameters
layer— Required. The float dom layer configuration.id— Optional. The float dom id, if not given will be auto generated.
Returns
float dom id and dispose function
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// You should register components at an appropriate time (e.g., when Univer is loaded).// This is a React component. For other frameworks, pass a matching adapter option, such as `{ framework: 'vue3' }`.univerAPI.registerComponent('myFloatDom', ({ data }) => ( <div style={{ width: '100%', height: '100%', background: '#fff', border: '1px solid #ccc', boxSizing: 'border-box', }} > popup content: {data?.label} </div>))// Add a floating DOM// If disposable is null, floating DOM addition failedconst disposable = fWorksheet.addFloatDomToPosition({ componentKey: 'myFloatDom', initPosition: { startX: 100, endX: 300, startY: 100, endY: 200, }, // Component data data: { label: 'hahah', },})console.log(disposable?.id) // The id of the floating DOM// Remove the floating DOM after 2 secondssetTimeout(() => { disposable?.dispose()}, 2000)Types: Nullable · IFICanvasFloatDom
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.addFloatDomToRange
Add dom over range to FloatDOM, And FloatDOM is registerComponent(BuiltInUIPart.CONTENT)
addFloatDomToRange(fRange: FRange, layer: IFICanvasFloatDom, domLayout: IDOMAnchor, id?: string): Nullable<{ id: string; dispose: () => void; }>Parameters
fRange— Required.layer— Required. The float dom layer configuration.domLayout— Required. The anchor configuration of the float dom.id— Optional. The float dom id, if not given will be auto generated
Returns
float dom id and dispose function
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Register a range loading componentconst RangeLoading = () => { const divStyle = { width: '100%', height: '100%', backgroundColor: '#fff', border: '1px solid #ccc', boxSizing: 'border-box' as const, display: 'flex', justifyContent: 'center', alignItems: 'center', textAlign: 'center' as const, transformOrigin: 'top left', } return <div style={divStyle}>Loading...</div>}univerAPI.registerComponent('RangeLoading', RangeLoading)// Add the range loading component covering the range A1:C3const fRange = fWorksheet.getRange('A1:C3')const disposable = fWorksheet.addFloatDomToRange( fRange, { componentKey: 'RangeLoading' }, {}, 'myRangeLoading',)console.log(disposable?.id) // The id of the floating DOM// Remove the floating DOM after 2 secondssetTimeout(() => { disposable?.dispose()}, 2000)// another example-------------------// Register a float button componentconst FloatButton = () => { const divStyle = { width: '100px', height: '30px', backgroundColor: '#fff', border: '1px solid #ccc', boxSizing: 'border-box' as const, display: 'flex', justifyContent: 'center', alignItems: 'center', textAlign: 'center' as const, cursor: 'pointer', } const clickHandler = () => { console.warn('click') } return ( <div style={divStyle} onClick={clickHandler}> FloatButton </div> )}univerAPI.registerComponent('FloatButton', FloatButton)// Add the float button to the range A5:C7, position is start from A5 cell, and width is 100px, height is 30px, margin is 100% of range width and heightconst fRange2 = fWorksheet.getRange('A5:C7')const disposable2 = fWorksheet.addFloatDomToRange( fRange2, { componentKey: 'FloatButton', }, { width: 100, height: 30, marginX: '100%', // margin percent to range width, or pixel marginY: '100%', }, 'myFloatButton',)console.log(disposable2?.id) // The id of the floating DOMTypes: Nullable · FRange · IFICanvasFloatDom · IDOMAnchor
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.batchUpdateFloatDoms
Batch update float doms
batchUpdateFloatDoms(updates: Array<{ id: string; config: Partial<Omit<IFCanvasFloatDomResult, 'id'>>; }>): thisParameters
updates— Required. array of update configs
Returns
The worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Update multiple float doms at onceconst allFloatDoms = fWorksheet.getAllFloatDoms()fWorksheet.batchUpdateFloatDoms( allFloatDoms.map((floatDom, index) => { if (floatDom.id === 'MyFloatDomId') { return { id: floatDom.id, config: { position: { left: 100, top: 100, }, data: { label: 'Updated', }, }, } } return { id: floatDom.id, config: { position: { left: 300, top: 100, }, }, } }),)Types: Array · Partial · Omit · IFCanvasFloatDomResult
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.getAllFloatDoms
Get all float doms in current worksheet
getAllFloatDoms(): IFCanvasFloatDomResult[]Returns
array of float dom info
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const allFloatDoms = fWorksheet.getAllFloatDoms()allFloatDoms.forEach((floatDom) => { console.log('Float dom ID:', floatDom.id) console.log('Position:', floatDom.position)})Types: IFCanvasFloatDomResult
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.getFloatDomById
Get float dom by id
getFloatDomById(id: string): Nullable<IFCanvasFloatDomResult>Parameters
id— Required. float dom id
Returns
float dom info or null if not found
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const floatDom = fWorksheet.getFloatDomById('myFloatDomId')if (floatDom) { console.log('Float dom position:', floatDom.position) console.log('Component key:', floatDom.componentKey) console.log('Custom data:', floatDom.data)}Types: IFCanvasFloatDomResult · Nullable
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.removeFloatDom
Remove float dom by id
removeFloatDom(id: string): thisParameters
id— Required. float dom id
Returns
The worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const firstFloatDom = fWorksheet.getAllFloatDoms()[0]if (!firstFloatDom) throw new Error('firstFloatDom is not available')// Remove the first float domfWorksheet.removeFloatDom(firstFloatDom.id)Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.saveCellImagesAsync
Save all cell images from specified ranges to the file system. This method will open a directory picker dialog and save all images to the selected directory.
saveCellImagesAsync(options?: ISaveCellImagesOptions, ranges?: FRange[]): Promise<boolean>Parameters
options— Optional. Options for saving imagesranges— Optional. The ranges to get cell images from. If not provided, all images in the worksheet will be saved.
Returns
True if images are saved successfully, otherwise false
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Save cell images from multiple rangesconst range1 = fWorksheet.getRange('A1:B10')const range2 = fWorksheet.getRange('D1:E10')// Save with default options (using cell address as file name)await fWorksheet.saveCellImagesAsync(undefined, [range1, range2])// Save with custom optionsawait fWorksheet.saveCellImagesAsync( { useCellAddress: true, useColumnIndex: 2, // Use values from column C for file names }, [range1, range2],)Types: Promise · ISaveCellImagesOptions · FRange
Package: @univerjs/sheets-drawing-ui · Type definitions
FWorksheet.updateFloatDom
Update float dom position and properties
updateFloatDom(id: string, config: Partial<Omit<IFCanvasFloatDomResult, 'id'>>): thisParameters
id— Required. float dom idconfig— Required. new float dom config
Returns
The worksheet instance for chaining
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const firstFloatDom = fWorksheet.getAllFloatDoms()[0]if (!firstFloatDom) throw new Error('firstFloatDom is not available')// Update first float dom position and sizefWorksheet.updateFloatDom(firstFloatDom.id, { position: { left: 100, top: 100, width: 200, height: 150, angle: 45, // rotate 45 degrees },})// Update first float dom datafWorksheet.updateFloatDom(firstFloatDom.id, { data: { label: 'Updated Label', color: '#ff0000', },})// Disable the first float dom from transformfWorksheet.updateFloatDom(firstFloatDom.id, { allowTransform: false,})Types: Partial · Omit · IFCanvasFloatDomResult
Package: @univerjs/sheets-drawing-ui · Type definitions
@univerjs/sheets-filter
FWorksheet.getFilter
Get the filter for the current worksheet.
getFilter(): FFilter | nullReturns
The interface class to handle the filter. If the worksheet does not have a filter,
this method would return null.
Examples
const workbook = univerAPI.getActiveWorkbook()const worksheet = workbook.getSheetByName('Sheet1')if (!worksheet) throw new Error('worksheet is not available')const filter = worksheet.getFilter()console.log(filter, filter?.getRange().getA1Notation())Types: FFilter
Package: @univerjs/sheets-filter · Type definitions
@univerjs/sheets-hyper-link
FWorksheet.getUrl
Create a hyperlink url to this sheet
getUrl(): stringReturns
The hyperlink url of this sheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const url = fWorksheet.getUrl()console.log(url)Package: @univerjs/sheets-hyper-link · Type definitions
@univerjs/sheets-note
FWorksheet.getNotes
Get all annotations in the worksheet
getNotes(): ISheetNote[]Returns
An array of all annotations in the worksheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const notes = fWorksheet.getNotes()console.log(notes)notes.forEach((item) => { const { row, col, note } = item console.log(`Cell ${fWorksheet.getRange(row, col).getA1Notation()} has a note: ${note}`)})Types: ISheetNote
Package: @univerjs/sheets-note · Type definitions
@univerjs/sheets-sort
FWorksheet.sort
Sort the worksheet by the specified column.
sort(colIndex: number, asc?: boolean): FWorksheetParameters
colIndex— Required. The column index to sort by.asc— Optional. Default:true. The sort order.truefor ascending,falsefor descending. The column A index is 0.
Returns
The worksheet itself for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Sorts the worksheet by the column A in ascending order.fWorksheet.sort(0)// Sorts the worksheet by the column A in descending order.fWorksheet.sort(0, false)Types: FWorksheet
Package: @univerjs/sheets-sort · Type definitions
@univerjs/sheets-table
FWorksheet.addTable
Add a table to the worksheet
addTable(tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<boolean> | booleanParameters
tableName— Required. The table namerangeInfo— Required. The table range informationtableId— Optional. The table idoptions— Optional. The table options
Returns
false for an invalid table name; otherwise, a promise resolving to whether the command succeeded.
Examples
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', columns: [{ id: 'col-1', displayName: 'Column 1' }], filters: [ { filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition, filterInfo: { conditionType: univerAPI.Enum.TableConditionTypeEnum.Number, compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan, expectedValue: 2, }, }, ],})if (success) { const tableInfo = fWorkbook.getTableInfo('id-1') console.log('debugger tableInfo', tableInfo)}Types: Promise · ITableRange · ITableOptions
Package: @univerjs/sheets-table · Type definitions
FWorksheet.addTableTheme
Add a theme to the table
addTableTheme(tableId: string, themeStyleJSON: IRangeThemeStyleJSON): Promise<boolean>Parameters
tableId— Required. The table idthemeStyleJSON— Required. The theme style JSON
Returns
Whether the theme was added successfully
Examples
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) { await fWorksheet.addTableTheme('id-1', { name: 'table-custom-1', headerRowStyle: { bg: { rgb: '#145f82', }, }, firstRowStyle: { bg: { rgb: '#c0e4f5', }, }, }) const tableInfo = fWorkbook.getTableInfo('id-1') console.log('debugger tableInfo', tableInfo)}Types: Promise · IRangeThemeStyleJSON
Package: @univerjs/sheets-table · Type definitions
FWorksheet.getSubTableInfos
Get the list of tables in the worksheet
getSubTableInfos(): ITableInfoWithUnitId[]Returns
The list of tables
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const tables = fWorksheet.getSubTableInfos()console.log('debugger tables', tables)Types: ITableInfoWithUnitId
Package: @univerjs/sheets-table · Type definitions
FWorksheet.getTableByCell
Get the table information by cell position
getTableByCell(row: number, column: number): ITableInfoWithUnitId | undefinedParameters
row— Required. The cell row index, starting from 0.column— Required. The cell column index, starting from 0.
Returns
The table information or undefined if not found
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const cellB2 = fWorksheet.getRange('B2')const row = cellB2.getRow()const column = cellB2.getColumn()console.log('debugger tableInfo', fWorksheet.getTableByCell(row, column))// 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',})console.log('debugger tableInfo2', fWorksheet.getTableByCell(row, column))Types: ITableInfoWithUnitId
Package: @univerjs/sheets-table · Type definitions
FWorksheet.removeTable
Remove a table from the worksheet
removeTable(tableId: string): Promise<boolean>Parameters
tableId— Required. The table id
Returns
Whether the table was removed successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const tableInfo = fWorkbook.getTableInfo('id-1')console.log('debugger tableInfo', tableInfo)if (tableInfo) { // Remove the table with the specified id await fWorksheet.removeTable('id-1')}Types: Promise
Package: @univerjs/sheets-table · Type definitions
FWorksheet.resetFilter
Reset the column filter of a table
resetFilter(tableId: string, column: number): Promise<boolean>Parameters
tableId— Required. The table idcolumn— Required. The column index, starting from 0. For example, the first column is 0, the second column is 1, and so on.
Returns
Whether the table filter was reset successfully
Examples
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 fWorksheet.setTableFilter('id-1', 1, { filterType: univerAPI.Enum.TableColumnFilterTypeEnum.condition, filterInfo: { conditionType: univerAPI.Enum.TableConditionTypeEnum.Number, compareType: univerAPI.Enum.TableNumberCompareTypeEnum.GreaterThan, expectedValue: 10, }, }) // Reset the filter for the second column after 3 seconds setTimeout(async () => { await fWorksheet.resetFilter('id-1', 1) }, 3000) const tableInfo = fWorkbook.getTableInfo('id-1') console.log('debugger tableInfo', tableInfo)}Types: Promise
Package: @univerjs/sheets-table · Type definitions
FWorksheet.setTableColumnFormula
Apply a formula to every data row of a table column, excluding header and footer. References are relative to the first data row. Empty string stops future auto-fill and preserves cells.
setTableColumnFormula(tableId: string, columnId: string, formula: string): booleanParameters
tableId— Required. Table ID in this worksheet.columnId— Required. Stable column ID from getSubTableInfos().formula— Required. Formula to apply, or an empty string to stop automatic filling.
Returns
Whether the undoable update succeeded synchronously.
Package: @univerjs/sheets-table · Type definitions
FWorksheet.setTableFilter
Set the filter for a table column
setTableFilter(tableId: string, column: number, filter: ITableFilterItem): Promise<boolean>Parameters
tableId— Required. The table idcolumn— Required. The table column index, starting from 0. For example, the first column is 0, the second column is 1, and so on.filter— Required. The filter item
Returns
Whether the table filter was set successfully
Examples
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 fWorksheet.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
FWorksheet.setTableFilterButtons
Update table filter button visibility without clearing filter criteria. Column overrides use stable column IDs from getSubTableInfos().
setTableFilterButtons(tableId: string, config: ITableFilterButtonConfig): booleanParameters
tableId— Required. Table ID in this worksheet.config— Required. Partial table and column button visibility settings.
Returns
Whether the update succeeded synchronously.
Types: ITableFilterButtonConfig
Package: @univerjs/sheets-table · Type definitions
FWorksheet.setTableName
Set the name of a table
setTableName(tableId: string, tableName: string): Promise<boolean> | booleanParameters
tableId— Required. The table idtableName— Required. The new table name
Returns
false for an invalid table name; otherwise, a promise resolving to whether the command succeeded.
Examples
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) { // Update the table name after 3 seconds setTimeout(async () => { await fWorksheet.setTableName('id-1', 'new-name') const tableInfo = fWorkbook.getTableInfo('id-1') console.log('debugger tableInfo', tableInfo) }, 3000)}Types: Promise
Package: @univerjs/sheets-table · Type definitions
FWorksheet.setTableRange
Set the range of a table
setTableRange(tableId: string, rangeInfo: ITableRange): Promise<boolean>Parameters
tableId— Required. The table idrangeInfo— Required. The new range information
Returns
Whether the table range was set successfully
Examples
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) { // Update the table range to B2:F21 after 3 seconds setTimeout(async () => { const newRange = fWorksheet.getRange('B2:F21') await fWorksheet.setTableRange('id-1', newRange.getRange()) const tableInfo = fWorkbook.getTableInfo('id-1') console.log('debugger tableInfo', tableInfo) }, 3000)}Types: Promise · ITableRange
Package: @univerjs/sheets-table · Type definitions
@univerjs/sheets-thread-comment
FWorksheet.clearComments
Clear all comments in the current sheet
clearComments(): Promise<boolean>Returns
Whether the comments are cleared successfully.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const result = await fWorksheet.clearComments()console.log(result)Types: Promise
Package: @univerjs/sheets-thread-comment · Type definitions
FWorksheet.getCommentById
get comment by comment id
getCommentById(commentId: string): FThreadComment | undefinedParameters
commentId— Required. comment id
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer')const commentBuilder = univerAPI.newTheadComment().setContent(richText).setId('mock-comment-id')const cell = fWorksheet.getRange('A1')await cell.addCommentAsync(commentBuilder)const comment = fWorksheet.getCommentById('mock-comment-id')console.log(comment, comment?.getCommentData())Types: FThreadComment
Package: @univerjs/sheets-thread-comment · Type definitions
FWorksheet.getComments
Get all comments in the current sheet
getComments(): FThreadComment[]Returns
All comments in the current sheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const comments = fWorksheet.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
FWorksheet.onCommented
Subscribe to comment events.
onCommented(callback: (params: IAddCommentCommandParams) => void): IDisposableParameters
callback— Required. Callback function, param contains comment info and target cell.
Returns
A disposable used to remove the listener.
Types: IDisposable · IAddCommentCommandParams
Package: @univerjs/sheets-thread-comment · Type definitions
@univerjs/sheets-ui
FWorksheet.autoResizeColumns
Sets the width of all columns starting at the given column position to fit their contents.
autoResizeColumns(startColumn: number, numColumns?: number): FWorksheetParameters
startColumn— Required. The position of the first column to resize. index starts at 0.numColumns— Optional. Default:1. The number of columns to auto-resize. Default is 1.
Returns
- The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set the A:C columns to a width that fits their text.fWorksheet.autoResizeColumns(0, 3)Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.autoResizeRows
Sets the height of all rows starting at the given row position to fit their contents.
autoResizeRows(startRow: number, numRows?: number): FWorksheetParameters
startRow— Required. The position of the first row to resize. index starts at 0.numRows— Optional. Default:1. The number of rows to auto-resize. Default is 1.
Returns
- The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set the first 3 rows to a height that fits their text.fWorksheet.autoResizeRows(0, 3)Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.customizeColumnHeader
Customize the column header of the worksheet.
customizeColumnHeader(cfg: IColumnsHeaderCfgParam): voidParameters
cfg— Required. The configuration of the column header.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.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
FWorksheet.customizeRowHeader
Customize the row header of the worksheet.
customizeRowHeader(cfg: IRowsHeaderCfgParam): voidParameters
cfg— Required. The configuration of the row header.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 12, }, rowsCfg: { 0: 'Moka II', 3: { text: 'Size', textAlign: 'left', // CanvasTextAlign }, },})Types: IRowsHeaderCfgParam
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.getScrollState
Get scroll state of current sheet.
getScrollState(): IScrollStateReturns
curr scroll state
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Scroll to cell D10const fRange = fWorksheet.getRange('D10')const row = fRange.getRow()const column = fRange.getColumn()fWorksheet.scrollToCell(row, column)// Get scroll stateconst scrollState = fWorksheet.getScrollState()const { offsetX, offsetY, sheetViewStartColumn, sheetViewStartRow } = scrollStateconsole.log(scrollState) // sheetViewStartRow: 9, sheetViewStartColumn: 3, offsetX: 0, offsetY: 0Types: IScrollState
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.getSkeleton
Get the skeleton service of the worksheet.
getSkeleton(): Nullable<SpreadsheetSkeleton>Returns
The skeleton of the worksheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const skeleton = fWorksheet.getSkeleton()console.log(skeleton)Types: SpreadsheetSkeleton · Nullable
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.getVisibleRange
Get visible range of main viewport.
getVisibleRange(): IRange | nullReturns
The visible range of the main viewport, or null if no sheet skeleton is available.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const visibleRange = fWorksheet.getVisibleRange()console.log(visibleRange)if (visibleRange) { console.log(fWorksheet.getRange(visibleRange).getA1Notation())}Types: IRange
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.getVisibleRangesOfAllViewports
Get visible ranges of all viewports.
getVisibleRangesOfAllViewports(): Map<SHEET_VIEWPORT_KEY, IRange> | nullReturns
Visible ranges keyed by viewport in a Map, or null if no sheet skeleton is available.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const visibleRanges = fWorksheet.getVisibleRangesOfAllViewports()console.log(visibleRanges)const mainLeftTopViewportRange = visibleRanges?.get( univerAPI.Enum.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,)if (mainLeftTopViewportRange) { console.log(fWorksheet.getRange(mainLeftTopViewportRange).getA1Notation())}Types: Map · SHEET_VIEWPORT_KEY · IRange
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.getZoom
Get the zoom ratio of the worksheet.
getZoom(): numberReturns
The zoom ratio of the worksheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const zoomRatio = fWorksheet.getZoom()console.log(zoomRatio)Package: @univerjs/sheets-ui · Type definitions
FWorksheet.highlightRanges
Highlight multiple ranges on the worksheet.
highlightRanges(ranges: FRange[], style?: Nullable<Partial<ISelectionStyle>>, primary?: Nullable<ISelectionCell>): IDisposableParameters
ranges— Required. The ranges to highlight.style— Optional. style for highlight ranges.primary— Optional. primary cell for highlight ranges.
Returns
An IDisposable to remove the highlights.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const ranges = [fWorksheet.getRange('A1:B2'), fWorksheet.getRange('D4:E5')]const disposable = fWorksheet.highlightRanges(ranges, { fill: 'yellow' })// To remove the highlights laterdisposable.dispose()Types: IDisposable · FRange · Nullable · Partial · ISelectionStyle · ISelectionCell
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.refreshCanvas
Refresh the canvas.
refreshCanvas(): FWorksheetReturns
The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.refreshCanvas()Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.scrollToCell
Scroll spreadsheet(viewMain) to cell position. Make the cell at topleft of current viewport. Based on the limitations of viewport and the number of rows and columns, you can only scroll to the maximum scrollable range.
scrollToCell(row: number, column: number, duration?: number): FWorksheetParameters
row— Required. Cell row indexcolumn— Required. Cell column indexduration— Optional. The duration of the scroll animation in milliseconds.
Returns
- The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Scroll to cell D10const fRange = fWorksheet.getRange('D10')const row = fRange.getRow()const column = fRange.getColumn()fWorksheet.scrollToCell(row, column)Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.setColumnHeaderHeight
Sets the height of the column header in pixels.
setColumnHeaderHeight(height: number): FWorksheetParameters
height— Required. The height to set.
Returns
- The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setColumnHeaderHeight(100)Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.setRowHeaderWidth
Sets the width of the row header in pixels.
setRowHeaderWidth(width: number): FWorksheetParameters
width— Required. The width to set.
Returns
- The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')fWorksheet.setRowHeaderWidth(100)Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
FWorksheet.zoom
Set zoom ratio of the worksheet.
zoom(zoomRatio: number): FWorksheetParameters
zoomRatio— Required. The zoom ratio to set.It should be in the range of 0.1 to 4.0.
Returns
The FWorksheet instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Set zoom ratio to 200%fWorksheet.zoom(2)const zoomRatio = fWorksheet.getZoom()console.log(zoomRatio) // 2Types: FWorksheet
Package: @univerjs/sheets-ui · Type definitions
@univerjs-pro/sheets-chart
FWorksheet.getChart
Returns a Chart on this worksheet by its stable Chart identifier.
getChart(chartId: string): FSheetChart | nullParameters
chartId— Required. The identifier returned byFSheetChart.getId.
Returns
A live Sheet Chart facade, or null if the Chart does not exist on this worksheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const firstChart = fWorksheet.getCharts()[0]const fChart = firstChart ? fWorksheet.getChart(firstChart.getId()) : nullconsole.log(fChart?.getInfo())Types: FSheetChart
Package: @univerjs-pro/sheets-chart · Type definitions
FWorksheet.getCharts
Returns all Charts on this worksheet.
getCharts(): FSheetChart[]Returns
Live Sheet Chart facades in the worksheet's model order.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const fCharts = fWorksheet.getCharts()fCharts.forEach((fChart) => { console.log(fChart.getId(), fChart.getInfo())})Types: FSheetChart
Package: @univerjs-pro/sheets-chart · Type definitions
FWorksheet.insertChart
Inserts a Chart into this worksheet from detached Chart information.
insertChart(info: ISheetChartInfo): Promise<FSheetChart>Parameters
info— Required. The Chart configuration, Sheet data source, and optional placement produced by a Chart builder.
Returns
A live facade for the inserted Sheet Chart.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const chartInfo = fWorksheet .newChart(univerAPI.Enum.ChartTypeString.Pie) .setSource('A1:B8') .setPosition('D2') .setSize(480, 320) .setDoughnutHole(0.4) .build()const fChart = await fWorksheet.insertChart(chartInfo)fChart.setPosition('E3')Types: FSheetChart · Promise · ISheetChartInfo
Package: @univerjs-pro/sheets-chart · Type definitions
FWorksheet.newChart
Creates a detached, type-specific Chart builder for this worksheet.
newChart<T extends ChartTypeString>(type: T): FSheetChartBuilderOf<T>Parameters
type— Required. The Chart type to create.
Returns
A detached builder that produces insertable Sheet Chart information.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const chartInfo = fWorksheet .newChart(univerAPI.Enum.ChartTypeString.Column) .setSource({ range: 'A1:D8', orientation: univerAPI.Enum.ChartSourceOrientation.Columns, }) .setPosition('F2') .setSize(640, 360) .setTitle('Quarterly sales') .build()const fChart = await fWorksheet.insertChart(chartInfo)console.log(fChart.getId())Types: FSheetChartBuilderOf
Package: @univerjs-pro/sheets-chart · Type definitions
@univerjs-pro/sheets-outline
FWorksheet.addColumnOutline
Add a column outline group to the current worksheet.
The column index is zero-based. The group covers numColumns columns starting at
startColumn, so addColumnOutline(0, 3) groups columns A to C.
Invalid groups are ignored and will not be added, including negative ranges,
zero or negative column counts, ranges outside the worksheet, crossing groups,
and groups that exceed the maximum outline depth.
addColumnOutline(startColumn: number, numColumns: number): FWorksheetParameters
startColumn— Required. The zero-based start column index of the outline group.numColumns— Required. The number of columns included in the outline group.
Returns
The current worksheet instance, allowing chained facade calls.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Group columns B to E.fWorksheet.addColumnOutline(1, 4)Types: FWorksheet
Package: @univerjs-pro/sheets-outline · Type definitions
FWorksheet.addRowOutline
Add a row outline group to the current worksheet.
The row index is zero-based. The group covers numRows rows starting at
startRow, so addRowOutline(1, 3) groups rows 2 to 4.
Invalid groups are ignored and will not be added, including negative ranges,
zero or negative row counts, ranges outside the worksheet, crossing groups,
and groups that exceed the maximum outline depth.
addRowOutline(startRow: number, numRows: number): FWorksheetParameters
startRow— Required. The zero-based start row index of the outline group.numRows— Required. The number of rows included in the outline group.
Returns
The current worksheet instance, allowing chained facade calls.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Group rows 2 to 6.fWorksheet.addRowOutline(1, 5)const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Facade methods return the worksheet, so calls can be chained.fWorksheet.addRowOutline(1, 5).addRowOutline(2, 2)Types: FWorksheet
Package: @univerjs-pro/sheets-outline · Type definitions
FWorksheet.clearDimensionOutlines
Clear outline groups in a row or column range.
The range uses zero-based indexes and is inclusive: [start, end]. Only outline
groups on the specified axis whose ranges are fully contained in this range are removed.
clearDimensionOutlines(axis: DimensionOutlineAxis, start: number, end: number): FWorksheetParameters
axis— Required. The outline axis to clear.start— Required. The zero-based inclusive start index of the clear range.end— Required. The zero-based inclusive end index of the clear range.
Returns
The current worksheet instance, allowing chained facade calls.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Remove row outline groups fully contained in rows 2 to 10.fWorksheet.clearDimensionOutlines(univerAPI.Enum.DimensionOutlineAxis.ROW, 1, 9)Types: FWorksheet · DimensionOutlineAxis
Package: @univerjs-pro/sheets-outline · Type definitions
FWorksheet.getDimensionOutlines
Get outline groups on the current worksheet.
When axis is omitted, both row and column outline groups are returned. The returned
array is a snapshot of the current outline data; use command or facade methods to make
changes instead of mutating the returned objects directly.
getDimensionOutlines(axis?: DimensionOutlineAxis): IDimensionOutline[]Parameters
axis— Optional. Optional outline axis filter.
Returns
The outline groups on the current worksheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rowOutlines = fWorksheet.getDimensionOutlines(univerAPI.Enum.DimensionOutlineAxis.ROW)rowOutlines.forEach((outline) => { console.log(outline.id, outline.start, outline.end, outline.collapsed)})const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const allOutlines = fWorksheet.getDimensionOutlines()const collapsedOutlines = allOutlines.filter((outline) => outline.collapsed)console.log('Collapsed outlines:', collapsedOutlines)Types: IDimensionOutline · DimensionOutlineAxis
Package: @univerjs-pro/sheets-outline · Type definitions
FWorksheet.removeDimensionOutline
Remove a row or column outline group from the current worksheet.
Use getDimensionOutlines() to read the current outline ids. Removing a parent outline
does not remove unrelated sibling outlines.
removeDimensionOutline(outlineId: string): FWorksheetParameters
outlineId— Required. The id of the outline group to remove.
Returns
The current worksheet instance, allowing chained facade calls.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const [firstRowOutline] = fWorksheet.getDimensionOutlines(univerAPI.Enum.DimensionOutlineAxis.ROW)if (firstRowOutline) { fWorksheet.removeDimensionOutline(firstRowOutline.id)}Types: FWorksheet
Package: @univerjs-pro/sheets-outline · Type definitions
FWorksheet.setDimensionOutlineCollapsed
Collapse or expand an existing row or column outline group.
Pass true to collapse the group and hide its grouped rows or columns. Pass false
to expand it and show the grouped rows or columns again, subject to other nested
collapsed groups.
setDimensionOutlineCollapsed(outlineId: string, collapsed: boolean): FWorksheetParameters
outlineId— Required. The id of the outline group to update.collapsed— Required. Whether the outline group should be collapsed.
Returns
The current worksheet instance, allowing chained facade calls.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const [firstColumnOutline] = fWorksheet.getDimensionOutlines( univerAPI.Enum.DimensionOutlineAxis.COLUMN,)if (firstColumnOutline) { // Collapse the group. fWorksheet.setDimensionOutlineCollapsed(firstColumnOutline.id, true) // Expand it later. fWorksheet.setDimensionOutlineCollapsed(firstColumnOutline.id, false)}Types: FWorksheet
Package: @univerjs-pro/sheets-outline · Type definitions
@univerjs-pro/sheets-pivot
FWorksheet.getPivotTableByCell
Get the pivot table id by the cell in current sheet.
getPivotTableByCell(row: number, col: number): FPivotTable | undefinedParameters
row— Required. The checked row.col— Required. The checked column.
Returns
The pivot table instance or undefined.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const pivotTable = fWorksheet.getPivotTableByCell(1, 1)if (pivotTable) { pivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)}Types: FPivotTable
Package: @univerjs-pro/sheets-pivot · Type definitions
@univerjs-pro/sheets-pivot-chart
FWorksheet.getPivotChart
Returns a PivotChart on this worksheet by its stable identifier.
getPivotChart(pivotChartId: string): FSheetPivotChart | nullParameters
pivotChartId— Required. The identifier returned byFSheetPivotChart.getId.
Returns
A live facade, or null if it is absent from this worksheet.
Types: FSheetPivotChart
Package: @univerjs-pro/sheets-pivot-chart · Type definitions
FWorksheet.getPivotCharts
Returns every PivotChart hosted by this worksheet.
getPivotCharts(): FSheetPivotChart[]Returns
Live PivotChart facades in model order.
Types: FSheetPivotChart
Package: @univerjs-pro/sheets-pivot-chart · Type definitions
FWorksheet.insertPivotChart
Inserts a PivotChart from detached Builder information.
insertPivotChart(info: ISheetPivotChartInfo): Promise<FSheetPivotChart>Parameters
info— Required. The PivotChart configuration, source, controls, and placement.
Returns
A live facade after the model and Drawing are created.
Throws
If the source, type, placement, or insertion is invalid.
Types: FSheetPivotChart · Promise · ISheetPivotChartInfo
Package: @univerjs-pro/sheets-pivot-chart · Type definitions
FWorksheet.newPivotChart
Creates a detached, type-specific PivotChart Builder for this worksheet.
newPivotChart<T extends PivotChartTypeString>(type: T): FSheetPivotChartBuilderOf<T>Parameters
type— Required. The supported Chart type.
Returns
A detached Builder that produces insertable PivotChart information.
Examples
import '@univerjs-pro/sheets-pivot-chart/facade'const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sales')const info = fWorksheet .newPivotChart(univerAPI.Enum.ChartTypeString.Column) .setSource('A1:G100') .setPosition('J2') .setSize(640, 360) .build()const fPivotChart = await fWorksheet.insertPivotChart(info)console.log(fPivotChart.getId())Types: FSheetPivotChartBuilderOf
Package: @univerjs-pro/sheets-pivot-chart · Type definitions
@univerjs-pro/sheets-shape
FWorksheet.getShape
Returns a worksheet Shape by its stable identifier.
getShape(shapeId: string): FSheetShape | FConnectorShape | nullParameters
shapeId— Required.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const fShape = fWorksheet.getShape('shape-1')console.log(fShape)Types: FSheetShape · FConnectorShape
Package: @univerjs-pro/sheets-shape · Type definitions
FWorksheet.getShapes
Returns all Shapes and Connectors on this worksheet.
getShapes(): Array<FSheetShape | FConnectorShape>Returns
An array of live Sheet Shape facades.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const fShapes = fWorksheet.getShapes()console.log(fShapes)Types: FSheetShape · FConnectorShape · Array
Package: @univerjs-pro/sheets-shape · Type definitions
FWorksheet.insertShape
Inserts a Shape or Connector into this worksheet.
insertShape(input: IShapeCreateInput): FSheetShape | FConnectorShape | nullParameters
input— Required. Common Shape creation input.
Returns
A live Sheet Shape facade, or null when creation fails.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook.')const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('Worksheet not found.')const fShape = fWorksheet.insertShape({ shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect, transform: { left: 120, top: 80, width: 240, height: 120 }, shapeData: { fill: { fillType: univerAPI.Enum.ShapeFillEnum.SolidFill, color: '#dbeafe' }, stroke: { lineStrokeType: univerAPI.Enum.ShapeLineTypeEnum.SolidLine, color: '#2563eb', width: 2, }, },})if (!fShape) throw new Error('Shape could not be inserted.')fShape .setRotation(8) .setStrokeLineDashType(univerAPI.Enum.ShapeLineDashEnum.Dash) .setAbsolutePosition(480, 160)fShape .getText() .setText('Sheet review') .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER) .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)Types: FSheetShape · FConnectorShape · IShapeCreateInput
Package: @univerjs-pro/sheets-shape · Type definitions
@univerjs-pro/sheets-sparkline
FWorksheet.addSparkline
Add sparkline to the worksheet.
addSparkline(sourceRanges: IRange[], targetRanges: IRange[], type: SparklineTypeEnum.LINE_CHART): FSparkline | undefinedParameters
sourceRanges— Required. Source data location for sparklinestargetRanges— Required. Where to place sparklinestype— Required. The type of Sparklines
Returns
Returns the sparkline instance for the next call
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a sparkline in the range A10, with the data source in the range A1:A7.const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]const targetRanges = [fWorksheet.getRange('A10').getRange()]const sparkline = fWorksheet.addSparkline( sourceRanges, targetRanges, univerAPI.Enum.SparklineTypeEnum.LINE_CHART,)console.log('sparkline instance', sparkline)Types: FSparkline · IRange · SparklineTypeEnum.LINE_CHART
Package: @univerjs-pro/sheets-sparkline · Type definitions
FWorksheet.composeSparkline
Group the sparklines in the selection into a new sparkline group
composeSparkline(ranges: IRange[]): voidParameters
ranges— Required. The selection range to be grouped
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a sparkline in the range A10, with the data source in the range A1:A7.const firstSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('A1:A7').getRange()], [fWorksheet.getRange('A10').getRange()],)// Create a sparkline in the range B10, with the data source in the range B1:B7.const secondSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('B1:B7').getRange()], [fWorksheet.getRange('B10').getRange()],)console.log('debugger', fWorksheet.getAllSubSparkline().size) // 2// Compose the two sparklines into one group after 3 secondssetTimeout(() => { fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()]) console.log('debugger', fWorksheet.getAllSubSparkline().size) // 1}, 3000)Types: IRange
Package: @univerjs-pro/sheets-sparkline · Type definitions
FWorksheet.getAllSubSparkline
Get all sparklines in the worksheet.
getAllSubSparkline(): Map<string, ISparklineGroup> | undefinedReturns
- The key is sparkline group id.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Get all sparklines in the current worksheetconst allSparkline = fWorksheet.getAllSubSparkline()console.log('allSparkline', allSparkline)Types: Map · ISparklineGroup
Package: @univerjs-pro/sheets-sparkline · Type definitions
FWorksheet.getSparklineByCell
Get the sparkline instance of the current cell
getSparklineByCell(row: number, col: number): FSparkline | undefinedParameters
row— Required. The row index of the cell, start at 0.col— Required. The column index of the cell, start at 0.
Returns
Returns the sparkline instance for the next call
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a sparkline in the range A10, with the data source in the range A1:A7.const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]const targetRanges = [fWorksheet.getRange('A10').getRange()]const sparkline = fWorksheet.addSparkline(sourceRanges, targetRanges)console.log('Cell A10: ', fWorksheet.getSparklineByCell(9, 0))console.log('Cell A11: ', fWorksheet.getSparklineByCell(10, 0))Types: FSparkline
Package: @univerjs-pro/sheets-sparkline · Type definitions
FWorksheet.getSparklineGroupByCell
Get the sparkline groups instance of the current cell
getSparklineGroupByCell(row: number, col: number): FSparklineGroup | undefinedParameters
row— Required. The row index of the cell, start at 0.col— Required. The column index of the cell, start at 0.
Returns
Returns the sparkline group instance for the next call
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a sparkline in the range A10, with the data source in the range A1:A7.const firstSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('A1:A7').getRange()], [fWorksheet.getRange('A10').getRange()],)// Create a sparkline in the range B10, with the data source in the range B1:B7.const secondSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('B1:B7').getRange()], [fWorksheet.getRange('B10').getRange()],)console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0))// Compose the two sparklines into one group after 3 secondssetTimeout(() => { fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()]) console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0))}, 3000)Types: FSparklineGroup
Package: @univerjs-pro/sheets-sparkline · Type definitions
FWorksheet.unComposeSparkline
Split the sparkline group within the current selection
unComposeSparkline(ranges: IRange[]): voidParameters
ranges— Required. The selection range to be ungrouped
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')// Create a sparkline in the range A10, with the data source in the range A1:A7.const firstSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('A1:A7').getRange()], [fWorksheet.getRange('A10').getRange()],)// Create a sparkline in the range B10, with the data source in the range B1:B7.const secondSparkline = fWorksheet.addSparkline( [fWorksheet.getRange('B1:B7').getRange()], [fWorksheet.getRange('B10').getRange()],)// Compose the two sparklines into one groupfWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()])console.log('debugger', fWorksheet.getAllSubSparkline().size) // 1// Uncompose the sparkline group after 3 secondssetTimeout(() => { fWorksheet.unComposeSparkline([fWorksheet.getRange('A10:B10').getRange()]) console.log('debugger', fWorksheet.getAllSubSparkline().size) // 2}, 3000)Types: IRange
Package: @univerjs-pro/sheets-sparkline · Type definitions
How is this guide?