Skip to Content
ClassesFWorksheet

Class: FWorksheet

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

Extends

  • FBaseInitialable.IFWorksheetFilter.IFWorksheetCommentMixin.IFWorksheetDataValidationMixin.IFWorksheetHyperlinkMixin.IFWorksheetConditionalFormattingMixin.IFWorksheetSort.IFWorksheetSparklineMixin.IFWorksheetSkeletonMixin.IFWorksheetLegacy.IFWorksheetChartMixin

Properties

PropertyTypeDescription

setActiveSelection

(range: FRange) => FWorksheet

Sets the active selection region for this sheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setActiveRange(fWorkSheet.getRange('A1'));

Methods

activate()

activate(): FWorksheet

Activates this sheet. Does not alter the sheet itself, only the parent’s notion of the active sheet.

Returns

FWorksheet

Current sheet, for chaining.


addConditionalFormattingRule()

addConditionalFormattingRule(rule): FWorksheet

Add a new conditional format

Parameters

ParameterTypeDescription
ruleIConditionFormattingRule

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Memberof

IFWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rule = worksheet?.createConditionalFormattingRule() .whenCellNotEmpty() .setRanges([{ startRow: 0, endRow: 100, startColumn: 0, endColumn: 100 }]) .setItalic(true) .setItalic(true) .setBackground('red') .setFontColor('green') .build(); worksheet?.addConditionalFormattingRule(rule!);

addFloatDomToColumnHeader()

addFloatDomToColumnHeader( column, layer, domPos, id?): Nullable<{ dispose: ...; id: ...; }>

Add dom at column header, And FloatDOM is registerComponent(BuiltInUIPart.CONTENT)

Parameters

ParameterTypeDescription
columnnumber
layerIFICanvasFloatDom
domPosIDOMAnchor
id?string

Returns

Nullable<{ dispose: …; id: …; }>

Example

{ const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const rs = sheet.addFloatDomToColumnHeader(3, { allowTransform: false, componentKey: 'FloatButton', // React comp key registered in ComponentManager props: { a: 1, }, }, {width: 100, height: 40, marginX: 0, marginY: 0, horizonOffsetAlign: 'right'}, 'ai-selector' // dom id ) }

Inherited from

IFWorksheetLegacy.addFloatDomToColumnHeader


addFloatDomToPosition()

addFloatDomToPosition(layer, id?): Nullable<{ dispose: ...; id: ...; }>

Add a float dom to position.

Parameters

ParameterTypeDescription
layerIFICanvasFloatDomfloat dom config
id?stringfloat dom id, if not given will be auto generated

Returns

Nullable<{ dispose: …; id: …; }>

float dom id and dispose function

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.addFloatDomToPosition({ allowTransform: false, initPosition: { startX: 200, endX: 400, startY: 200, endY: 400, }, componentKey: 'ImageDemo', props: { a: 1, }, data: { aa: '128', }, });

Inherited from

IFWorksheetLegacy.addFloatDomToPosition


addFloatDomToRange()

addFloatDomToRange( range, layer, domLayout, id?): Nullable<{ dispose: ...; id: ...; }>

Add dom over range to FloatDOM, And FloatDOM is registerComponent(BuiltInUIPart.CONTENT)

Parameters

ParameterTypeDescription
rangeFRange-
layerIFICanvasFloatDom
domLayoutIDOMAnchor-
id?string

Returns

Nullable<{ dispose: …; id: …; }>

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const range = sheet.getRange(0, 0, 3, 3); univerAPI.getActiveWorkbook().setActiveRange(range); const {id, dispose } = sheet.addFloatDomToRange(range, { allowTransform: false, componentKey: 'RangeLoading', props: { a: 1, }, data: { aa: '128', }, }, {}, 'loadingcover' ) setTimeout(()=> { dispose(); }, 2000) // another example------------------- { const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const range = univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange() const {id, dispose } = sheet.addFloatDomToRange(range, { allowTransform: false, componentKey: 'FloatButton', // React comp key registered in ComponentManager props: { a: 1, }, data: { aa: '128', }, }, { width: 100, height: 30, marginX: '100%', // margin percent to range width, or pixel marginY: '100%' }, 'AIButton') // dom id }

Inherited from

IFWorksheetLegacy.addFloatDomToRange


addSparkline()

addSparkline( sourceRanges, targetRanges, type): FSparkline

Parameters

ParameterTypeDescription
sourceRangesIRange[]Source data location for sparklines
targetRangesIRange[]Where to place sparklines
typeLINE_CHARTThe type of Sparklines

Returns

FSparkline

Returns the sparkline instance for the next call

Description

Add sparkline to the worksheet.

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const sparkline = worksheet.addSparkline( [{ startRow: 0, endRow: 6, startColumn: 0, endColumn: 0 }], [{ startRow: 9, endRow: 9, startColumn: 0, endColumn: 0 }] ); console.log('sparkline instance', sparkline);

autoFitRow()

autoFitRow(rowPosition, auto?): FWorksheet

Make certain row wrap and auto height.

Parameters

ParameterTypeDescription
rowPositionnumber
auto?BooleanNumber

Returns

FWorksheet

this

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.autoFitRow(24);

cancelFreeze()

cancelFreeze(): FWorksheet

Cancels the frozen state of the current sheet.

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); // Cancel freeze sheet.cancelFreeze();

clear()

clear(options?): FWorksheet

Clears the sheet of content and formatting information.Or Optionally clears only the contents or only the formatting.

Parameters

ParameterTypeDescription
options?IFacadeClearOptionsOptions for clearing the sheet. If not provided, the contents and formatting are cleared both.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // clear the sheet of content and formatting information fWorkSheet.clear(); // clear the sheet of content only fWorkSheet.clear({ contentsOnly: true });

clearComments()

clearComments(): Promise<boolean>

Clear all comments in the current sheet

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getSheetById(sheetId); await worksheet.clearComments();

Returns

Promise<boolean>


clearContents()

clearContents(): FWorksheet

Clears the sheet of contents, while preserving formatting information.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // clear the sheet of content only fWorkSheet.clearContents();

clearFormats()

clearFormats(): FWorksheet

Clears the sheet of formatting, while preserving contents.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // clear the sheet of formatting only fWorkSheet.clearFormats();

composeSparkline()

composeSparkline(ranges): void

Parameters

ParameterTypeDescription
rangesIRange[]Current selection

Returns

void

Description

Group the sparklines in the selection into a new sparkline group

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const firstSparkline = worksheet.addSparkline( [{ startRow: 0, endRow: 6, startColumn: 0, endColumn: 0 }], [{ startRow: 9, endRow: 9, startColumn: 0, endColumn: 0 }] ); const secondSparkline = worksheet.addSparkline( [{ startRow: 0, endRow: 6, startColumn: 0, endColumn: 0 }], [{ startRow: 9, endRow: 9, startColumn: 1, endColumn: 1 }] ); // There will be two sparklines here const allSparklineBeforeCompose = worksheet.getAllSubSparkline(); worksheet.composeSparkline([{ startRow: 9, endRow: 9, startColumn: 0, endColumn: 1 }]); // After compose, there will only be one sparkline const allSparklineAfterCompose = worksheet.getAllSubSparkline(); console.log('debugger', allSparklineBeforeCompose, allSparklineAfterCompose);

createConditionalFormattingRule()

createConditionalFormattingRule(): FConditionalFormattingBuilder

Returns

FConditionalFormattingBuilder

Deprecated

use newConditionalFormattingRule instead. Creates a constructor for conditional formatting

Memberof

IFWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rule = worksheet?.createConditionalFormattingRule() .whenCellNotEmpty() .setRanges([{ startRow: 0, endRow: 100, startColumn: 0, endColumn: 100 }]) .setItalic(true) .setItalic(true) .setBackground('red') .setFontColor('green') .build();

customizeColumnHeader()

customizeColumnHeader(cfg): void

Customize the column header of the spreadsheet.

Parameters

ParameterTypeDescription
cfgIColumnsHeaderCfgParamThe configuration of the column header.

Returns

void

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); 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' } });

customizeRowHeader()

customizeRowHeader(cfg): void

Customize the row header of the spreadsheet.

Parameters

ParameterTypeDescription
cfgIRowsHeaderCfgParamThe configuration of the row header.

Returns

void

Example

univerAPI.customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 12 }, rowsCfg: { 0: 'MokaII', 3: { text: 'Size', textAlign: 'left' } } });

deleteColumn()

deleteColumn(columnPosition): FWorksheet

Deletes the column at the given column position.

Parameters

ParameterTypeDescription
columnPositionnumberThe position of the column, starting at 0 for the first column

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Delete column C sheet.deleteColumn(2); // Delete column A sheet.deleteColumn(0);

deleteColumns()

deleteColumns(columnPosition, howMany): FWorksheet

Deletes a number of columns starting at the given column position.

Parameters

ParameterTypeDescription
columnPositionnumberThe position of the first column to delete, starting at 0 for the first column
howManynumberThe number of columns to delete

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Delete 3 columns at column index 2 (columns C, D, E) sheet.deleteColumns(2, 3); // Delete 1 column at column index 0 (column A) sheet.deleteColumns(0, 1);

deleteConditionalFormattingRule()

deleteConditionalFormattingRule(cfId): FWorksheet

Delete conditional format according to cfId

Parameters

ParameterTypeDescription
cfIdstring

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Memberof

IFWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rules = worksheet?.getConditionalFormattingRules(); worksheet?.deleteConditionalFormattingRule(rules![0].cfId);

deleteImages()

deleteImages(sheetImages): FWorksheet

Parameters

ParameterType
sheetImagesFOverGridImage[]

Returns

FWorksheet

Inherited from

IFWorksheetLegacy.deleteImages


deleteRow()

deleteRow(rowPosition): FWorksheet

Deletes the row at the given row position.

Parameters

ParameterTypeDescription
rowPositionnumberThe position of the row, starting at 0 for the first row.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Delete 3 rows at row index 2 (rows 3-5) sheet.deleteRow(2); // Delete 1 row at row index 0 (first row) sheet.deleteRow(0);

deleteRows()

deleteRows(rowPosition, howMany): FWorksheet

Deletes a number of rows starting at the given row position.

Parameters

ParameterTypeDescription
rowPositionnumberThe position of the first row to delete, starting at 0 for the first row.
howManynumberThe number of rows to delete.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Delete 3 rows at row index 2 (rows 3-5) sheet.deleteRows(2, 3); // Delete 1 row at row index 0 (first row) sheet.deleteRows(0);

equalTo()

equalTo(other): boolean

Judge whether provided FWorksheet is equal to current.

Parameters

ParameterTypeDescription
otherFWorksheetthe FWorksheet to compare with.

Returns

boolean

true if the FWorksheet is equal to the current FWorksheet, false otherwise.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const fWorkSheet2 = fWorkbook.getSheetByName('Sheet1'); console.log(fWorkSheet.equals(fWorkSheet2)); // true, if the active sheet is 'Sheet1'

getActiveImages()

getActiveImages(): FOverGridImage[]

Get all images in current sheet.

Returns

FOverGridImage[]

FOverGridImage[]

Example

univerAPI.getActiveWorkbook().getActiveSheet().getImages();

Inherited from

IFWorksheetLegacy.getActiveImages


getActiveRange()

getActiveRange(): FRange

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

Returns

FRange

the active range

Example

const sheet = workbook.getActiveSheet(); // Get the currently active range const activeRange = sheet.getActiveRange(); if (activeRange) { console.log('Active range:', activeRange.getA1Notation()); }

getAllSubSparkline()

getAllSubSparkline(): Map<string, ISparklineGroup>

Returns

Map<string, ISparklineGroup>

Description

Get all sparklines in the worksheet.

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const allSparkline = worksheet.getAllSubSparkline(); console.log('allSparkline', allSparkline);

getCellMergeData()

getCellMergeData(row, column): FRange

Get the merged cell data of the specified row and column.

Parameters

ParameterTypeDescription
rownumberThe row index
columnnumberThe column index

Returns

FRange

The merged cell data, or undefined if the cell is not merged

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const merge = fWorkSheet.getCellMergeData(0, 0); if (merge) { console.log('Merged range:', merge.getA1Notation()); }

getCharts()

getCharts(): FChart[]

Returns an array of charts on this sheet.

Returns

FChart[]

  • An array of charts on this sheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); const charts = fSheet.getCharts(); console.log(charts.length); //chart count

getColumnCustomMetadata()

getColumnCustomMetadata(index): CustomData

Get custom metadata of column

Parameters

ParameterTypeDescription
indexnumbercolumn index

Returns

CustomData

custom metadata

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const custom = fWorkSheet.getColumnCustomMetadata(0);

getColumnDefaultStyle()

getColumnDefaultStyle(index, keepRaw?): string | Nullable<...>

Get the default style of the worksheet column

Parameters

ParameterTypeDescription
indexnumberThe column index
keepRaw?booleanIf true, return the raw style data maybe the style name or style data, otherwise return the data from col manager

Returns

string | Nullable<…>

The default style of the worksheet column name or style data

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); // Get default style for column 0 (A) const colStyle = sheet.getColumnDefaultStyle(0); // Get raw style data for column 0 const rawColStyle = sheet.getColumnDefaultStyle(0, true);

getCommentById()

getCommentById(commentId): FThreadComment

get comment by comment id

Parameters

ParameterTypeDescription
commentIdstringcomment id const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getSheetById(sheetId); const comment = worksheet.getCommentById(commentId);

Returns

FThreadComment


getComments()

getComments(): FThreadComment[]

Get all comments in the current sheet

Returns

FThreadComment[]

all comments in the current sheet

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getSheetById(sheetId); const comments = worksheet.getComments();

getConditionalFormattingRules()

getConditionalFormattingRules(): IConditionFormattingRule[]

Gets all the conditional formatting for the current sheet

Returns

IConditionFormattingRule[]

{IConditionFormattingRule[]}

Memberof

IFWorksheetConditionalFormattingMixin

Example

univerAPI.getActiveWorkbook()?.getActiveSheet().getConditionalFormattingRules();

getDataRange()

getDataRange(): FRange

Returns a Range corresponding to the dimensions in which data is present. This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).

Returns

FRange

The range of the data in the sheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // the sheet is a empty sheet const cellRange = fWorkSheet.getRange(200, 10, 1, 1); cellRange.setValue('Hello World'); console.log(fWorkSheet.getDataRange().getA1Notation()); // A1:J200

getDataValidation()

getDataValidation(ruleId): Nullable<FDataValidation>

get data validation rule by rule id

Parameters

ParameterTypeDescription
ruleIdstringthe rule id

Returns

Nullable<FDataValidation>

data validation rule

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getWorksheet('sheet1'); const dataValidation = worksheet.getDataValidation('ruleId');

getDataValidations()

getDataValidations(): FDataValidation[]

Get all data validation rules in current sheet.

Returns

FDataValidation[]

all data validation rules

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getWorksheet('sheet1'); const dataValidations = worksheet.getDataValidations();

getDefaultStyle()

getDefaultStyle(): string | Nullable<...>

Get the default style of the worksheet

Returns

string | Nullable<…>

Default style of the worksheet.

Example

const sheet = workbook.getActiveSheet(); const defaultStyle = sheet.getDefaultStyle();

getDefinedNames()

getDefinedNames(): FDefinedName[]

Get all the defined names in the worksheet.

Returns

FDefinedName[]

All the defined names in the worksheet

Example

// The code below gets all the defined names in the worksheet const activeSpreadsheet = univerAPI.getActiveWorkbook(); const sheet1 = activeSpreadsheet.getSheetByName('Sheet1'); const definedNames = sheet1.getDefinedNames();

getFilter()

getFilter(): FFilter

Get the filter for the current worksheet.

Returns

FFilter

The interface class to handle the filter. If the worksheet does not have a filter, this method would return null.

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const filter = worksheet.getFilter();

getFreeze()

getFreeze(): IFreeze

Get the freeze state of the current sheet.

Returns

IFreeze

The freeze state of the current sheet

Example

const sheet = workbook.getActiveSheet(); // Get the freeze state of the current sheet const freeze = sheet.getFreeze(); console.log(freeze);

getFrozenColumnRange()

getFrozenColumnRange(): IColumnRange

Get freezed columns

Returns

IColumnRange

The range of the frozen columns.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // Get the range of the frozen columns const frozenColumns = fWorkSheet.getFrozenColumnRange(); console.log(frozenColumns);

getFrozenColumns()

getFrozenColumns(): number

Get the number of frozen columns.

Returns

number

The number of frozen columns, returns 0 if no columns are frozen.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // Get the number of frozen columns const frozenColumns = fWorkSheet.getFrozenColumns(); console.log(frozenColumns);

getFrozenRowRange()

getFrozenRowRange(): IRowRange

Get freezed rows.

Returns

IRowRange

The range of the frozen rows.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // Get the range of the frozen rows const frozenRows = fWorkSheet.getFrozenRowRange(); console.log(frozenRows);

getFrozenRows()

getFrozenRows(): number

Get the number of frozen rows.

Returns

number

The number of frozen rows. returns 0 if no rows are frozen.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // Get the number of frozen rows const frozenRows = fWorkSheet.getFrozenRows(); console.log(frozenRows);

getGridLinesColor()

getGridLinesColor(): string

Get the color of the gridlines in the sheet.

Returns

string

The color of the gridlines in the sheet or undefined. The default color is ‘rgb(214, 216, 219)’.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // get the gridlines color of the sheet console.log(fWorkSheet.getGridLinesColor());

getImageById()

getImageById(id): FOverGridImage

Get image by drawing id

Parameters

ParameterTypeDescription
idstringThe drawing id of the image

Returns

FOverGridImage

FOverGridImage | null

Example

univerAPI.getActiveWorkbook().getActiveSheet().getImageById('xxxx');

Inherited from

IFWorksheetLegacy.getImageById


getImages()

getImages(): FOverGridImage[]

Get all images in current sheet.

Returns

FOverGridImage[]

FOverGridImage[]

Example

univerAPI.getActiveWorkbook().getActiveSheet().getImages();

Inherited from

IFWorksheetLegacy.getImages


getIndex()

getIndex(): number

Gets the position of the sheet in its parent spreadsheet. Starts at 0.

Returns

number

The position of the sheet in its parent spreadsheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // get the position of the active sheet const position = fWorkSheet.getIndex(); console.log(position); // 0

getInject()

getInject(): Injector

Returns the injector

Returns

Injector

The injector

Example

const injector = univerAPI.getActiveWorkbook().getActiveSheet().getInject();

getLastColumn()

getLastColumn(): number

Returns

number

the last column of the sheet that contains content.

Deprecated

use getLastColumn instead. Returns the position of the last column that has content. Same as getLastColumns.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const fRange = fWorkSheet.getRange(100, 20, 1, 1); console.log(fWorkSheet.getLastColumn());

getLastColumns()

getLastColumns(): number

Returns the position of the last column that has content.

Returns

number

the last column of the sheet that contains content.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const fRange = fWorkSheet.getRange(100, 20, 1, 1); console.log(fWorkSheet.getLastColumns()); // 20

getLastRow()

getLastRow(): number

Returns the position of the last row that has content, same as getLastRows().

Returns

number

the last row of the sheet that contains content.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const fRange = fWorkSheet.getRange(100,1,1,1); fRange.setValue('Hello World'); console.log(fWorkSheet.getLastRow()); *** ### ~~getLastRows()~~ ```ts getLastRows(): number

Returns

number

the last row of the sheet that contains content.

Deprecated

use getLastRow instead. Returns the position of the last row that has content.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const fRange = fWorkSheet.getRange(100,1,1,1); fRange.setValue('Hello World'); console.log(fWorkSheet.getLastRows()); // 100 *** ### getMaxColumns() ```ts getMaxColumns(): number

Returns the current number of columns in the sheet, regardless of content.

Returns

number

The maximum columns count of the sheet

Example

const sheet = workbook.getActiveSheet(); const totalColumns = sheet.getMaxColumns(); console.log(`Sheet has ${totalColumns} columns`);

getMaxRows()

getMaxRows(): number

Returns the current number of rows in the sheet, regardless of content.

Returns

number

The maximum rows count of the sheet

Example

const sheet = workbook.getActiveSheet(); const totalRows = sheet.getMaxRows(); console.log(`Sheet has ${totalRows} rows`);

getMergeData()

getMergeData(): FRange[]

Get all merged cells in the current worksheet

Returns

FRange[]

All the merged cells in the worksheet

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const rangeFirst = worksheet.getRange(0, 0, 2, 2); const mergeFirst = rangeFirst.merge(); const rangeSecond = worksheet.getRange(5, 0, 2, 2); const mergeSecond = rangeSecond.merge(); const mergeData = worksheet.getMergeData(); console.log('debugger', mergeData);

getMergedRanges()

getMergedRanges(): FRange[]

Get all merged cells in the current sheet

Returns

FRange[]

all merged cells

Example

const sheet = workbook.getActiveSheet(); // Get all merged ranges in the sheet const mergedRanges = sheet.getMergedRanges(); // Process each merged range mergedRanges.forEach(range => { console.log(range.getA1Notation()); });

getRange()

Call Signature

getRange(row, column): FRange

Returns a Range object representing a single cell at the specified row and column.

Parameters
ParameterTypeDescription
rownumberThe row index of the cell.
columnnumberThe column index of the cell.
Returns

FRange

A Range object representing the specified cell.

Example
const sheet = workbook.getActiveSheet(); // Get range for cell at row 0, column 0 (A1) const range = sheet.getRange(0, 0);

Call Signature

getRange( row, column, numRows): FRange

Returns a Range object representing a range starting at the specified row and column, with the specified number of rows.

Parameters
ParameterTypeDescription
rownumberThe starting row index of the range.
columnnumberThe starting column index of the range.
numRowsnumberThe number of rows in the range.
Returns

FRange

A Range object representing the specified range.

Call Signature

getRange( row, column, numRows, numColumns): FRange

Returns a Range object representing a range starting at the specified row and column, with the specified number of rows and columns.

Parameters
ParameterTypeDescription
rownumberThe starting row index of the range.
columnnumberThe starting column index of the range.
numRowsnumberThe number of rows in the range.
numColumnsnumberThe number of columns in the range.
Returns

FRange

A Range object representing the specified range.

Call Signature

getRange(a1Notation): FRange

Returns a Range object specified by A1 notation.

Parameters
ParameterTypeDescription
a1NotationstringA string representing a range in A1 notation.
Returns

FRange

A Range object representing the specified range.

Example
const sheet = workbook.getActiveSheet(); // Get range for cells A1:C3 const range = sheet.getRange("A1:C3"); // Get range for a single cell const cell = sheet.getRange("B2"); // Get range with sheet name const rangeWithSheet = sheet.getRange("Sheet1!A1:C3");

Call Signature

getRange(range): FRange

Returns a Range object for the specified range.

Parameters
ParameterTypeDescription
rangeIRangeThe range specification.
Returns

FRange

A Range object representing the specified range.


getRowCustomMetadata()

getRowCustomMetadata(index): CustomData

Get custom metadata of row

Parameters

ParameterTypeDescription
indexnumberrow index

Returns

CustomData

custom metadata

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); const custom = fWorkSheet.getRowCustomMetadata(0);

getRowDefaultStyle()

getRowDefaultStyle(index, keepRaw?): string | Nullable<...>

Get the default style of the worksheet row

Parameters

ParameterTypeDescription
indexnumberThe row index
keepRaw?booleanIf true, return the raw style data maybe the style name or style data, otherwise return the data from row manager

Returns

string | Nullable<…>

The default style of the worksheet row name or style data

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); // Get default style for row 0 (1) const rowStyle = sheet.getRowDefaultStyle(0); // Get raw style data for row 0 const rawRowStyle = sheet.getRowDefaultStyle(0, true);

getScrollState()

getScrollState(): IScrollState

Get scroll state of current sheet.

Returns

IScrollState

curr scroll state

Example

univerAPI.getActiveWorkbook().getActiveSheet().getScrollState()

getSelection()

getSelection(): FSelection

Represents the selection ranges info of the worksheet.

Returns

FSelection

return the current selections of the worksheet or null if there is no selection.

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const selections = sheet.getSelection();

getSheet()

getSheet(): Worksheet

Returns the worksheet

Returns

Worksheet

The worksheet instance.

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet().getSheet();

getSheetId()

getSheetId(): string

Returns the worksheet id.

Returns

string

The id of the worksheet.

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const id = sheet.getSheetId();

getSheetName()

getSheetName(): string

Returns the worksheet name.

Returns

string

The name of the worksheet.

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); const name = sheet.getSheetName();

getSkeleton()

getSkeleton(): any

Get the skeleton service of the worksheet.

Returns

any

The skeleton of the worksheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const skeleton = fWorksheet.getSkeleton(); console.log(skeleton);

getSparklineByCell()

getSparklineByCell(row, col): FSparkline

Parameters

ParameterTypeDescription
rownumber
colnumber

Returns

FSparkline

Returns the sparkline instance for the next call

Description

Get the sparkline instance of the current cell

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const sparkline = worksheet.getSparklineByCell(9, 0)

getSparklineGroupByCell()

getSparklineGroupByCell(row, col): FSparklineGroup

Parameters

ParameterTypeDescription
rownumber
colnumber

Returns

FSparklineGroup

Description

Get the sparkline groups instance of the current cell

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const sparkline = worksheet.getSparklineGroupByCell(9, 0)

getTabColor()

getTabColor(): string

Get the tab color of the sheet.

Returns

string

The tab color of the sheet or undefined. The default color is css style property ‘unset’.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // get the tab color of the sheet console.log(fWorkSheet.getTabColor());

getUrl()

getUrl(): string

Get the url of this sheet

Returns

string


getValidatorStatus()

getValidatorStatus(): Promise<ObjectMatrix<...>>

Returns

Promise<ObjectMatrix<…>>

Deprecated

use getValidatorStatusAsync instead


getValidatorStatusAsync()

getValidatorStatusAsync(): Promise<ObjectMatrix<...>>

Get data validation validator status for current sheet.

Returns

Promise<ObjectMatrix<…>>

matrix of validator status

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getWorksheet('sheet1'); const validatorStatus = worksheet.getValidatorStatus();

getVisibleRange()

getVisibleRange(): IRange

Return visible range, sum view range of 4 viewports.

Returns

IRange

  • visible range

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const visibleRange = fWorksheet.getVisibleRange();

getWorkbook()

getWorkbook(): Workbook

Returns the workbook

Returns

Workbook

The workbook instance.

Example

const workbook = univerAPI.getActiveWorkbook().getWorkbook();

getZoom()

getZoom(): number

Get the zoom ratio of the worksheet.

Returns

number

The zoom ratio of the worksheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const zoomRatio = fWorksheet.getZoom(); console.log(zoomRatio);

hasHiddenGridLines()

hasHiddenGridLines(): boolean

Returns true if the sheet’s gridlines are hidden; otherwise returns false. Gridlines are visible by default.

Returns

boolean

True if the sheet’s gridlines are hidden; otherwise false.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // check if the gridlines are hidden if (fWorkSheet.hasHiddenGridLines()) { console.log('Gridlines are hidden'); }

hideColumn()

hideColumn(column): FWorksheet

Hides the column or columns in the given range.

Parameters

ParameterTypeDescription
columnFRangeThe column range to hide

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Hide columns C, D, E sheet.hideColumn({ startColumn: 2, endColumn: 4 }); // Hide column A sheet.hideColumn({ startColumn: 0, endColumn: 0 });

hideColumns()

hideColumns(columnIndex, numColumn?): FWorksheet

Hides one or more consecutive columns starting at the given index. Use 0-index for this method

Parameters

ParameterTypeDescription
columnIndexnumberThe starting index of the columns to hide
numColumn?numberThe number of columns to hide

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Hide columns C, D, E sheet.hideColumns(2, 3); // Hide column A sheet.hideColumns(0, 1);

hideRow()

hideRow(row): FWorksheet

Hides the rows in the given range.

Parameters

ParameterTypeDescription
rowFRangeThe row range to hide.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Hide 3 rows starting from row index 1 (rows 2-4) sheet.hideRow(1); // Hide single row at index 0 (first row) sheet.hideRow(0);

hideRows()

hideRows(rowIndex, numRow?): FWorksheet

Hides one or more consecutive rows starting at the given index. Use 0-index for this method

Parameters

ParameterTypeDescription
rowIndexnumberThe starting index of the rows to hide
numRow?numberThe number of rows to hide

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Hide 3 rows starting from row index 1 (rows 2-4) sheet.hideRows(1, 3); // Hide single row at index 0 (first row) sheet.hideRows(0);

hideSheet()

hideSheet(): FWorksheet

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.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // hide the active sheet fWorkSheet.hideSheet();

insertChart()

insertChart(chartBuildInfo): Promise<FChart>

Adds a new chart to this sheet.

Parameters

ParameterTypeDescription
chartBuildInfoIChartBuilderInfoThe chart builder info.

Returns

Promise<FChart>

  • The new chart.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); const chartInfo = fSheet.newChart() .addRange('A1:B8') .setChartType(ChartTypeBits.Column) .setPosition(1, 1, 0, 0) .build(); const fChart = await fSheet.insertChart(chartInfo);

insertColumnAfter()

insertColumnAfter(afterPosition): FWorksheet

Inserts a column after the given column position.

Parameters

ParameterTypeDescription
afterPositionnumberThe column after which the new column should be added, starting at 0 for the first column

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); // Insert 3 columns at column index 2 (before column C) sheet.insertColumnAfter(2); // Insert 1 column at column index 0 (before column A) sheet.insertColumnAfter(0);

insertColumnBefore()

insertColumnBefore(beforePosition): FWorksheet

Inserts a column before the given column position.

Parameters

ParameterTypeDescription
beforePositionnumberThe column before which the new column should be added, starting at 0 for the first column

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); // Insert 3 columns at column index 2 (before column C) sheet.insertColumnBefore(2); // Insert 1 column at column index 0 (before column A) sheet.insertColumnBefore(0);

insertColumns()

insertColumns(columnIndex, numColumns?): FWorksheet

Inserts one or more consecutive blank columns in a sheet starting at the specified location.

Parameters

ParameterTypeDescription
columnIndexnumberThe index indicating where to insert a column, starting at 0 for the first column
numColumns?numberThe number of columns to insert

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Insert 3 columns at column index 2 (before column C) sheet.insertColumns(2, 3); // Insert 1 column at column index 0 (before column A) sheet.insertColumns(0);

insertColumnsAfter()

insertColumnsAfter(afterPosition, howMany): FWorksheet

Inserts a given number of columns after the given column position.

Parameters

ParameterTypeDescription
afterPositionnumberThe column after which the new columns should be added, starting at 0 for the first column
howManynumberThe number of columns to insert

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Insert 3 columns at column index 2 (before column C) sheet.insertColumnsAfter(2, 3); // Insert 1 column at column index 0 (before column A) sheet.insertColumnsAfter(0, 1);

insertColumnsBefore()

insertColumnsBefore(beforePosition, howMany): FWorksheet

Inserts a number of columns before the given column position.

Parameters

ParameterTypeDescription
beforePositionnumberThe column before which the new columns should be added, starting at 0 for the first column
howManynumberThe number of columns to insert

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Insert 3 columns at column index 2 (before column C) sheet.insertColumnsBefore(2, 3); // Insert 1 column at column index 0 (before column A) sheet.insertColumnsBefore(0, 1);

insertDefinedName()

insertDefinedName(name, formulaOrRefString): void

Parameters

ParameterType
namestring
formulaOrRefStringstring

Returns

void


insertImage()

Call Signature

insertImage(url): Promise<boolean>

Insert an image to the sheet

Parameters
ParameterTypeDescription
urlstringThe image url
Returns

Promise<boolean>

true if the image is inserted successfully

Example
const activeSpreadsheet = univerAPI.getActiveWorkbook(); const activeSheet = activeSpreadsheet.getActiveSheet(); activeSheet.insertImage('https://avatars.githubusercontent.com/u/61444807?s=48&v=4', 5, 5, 0, 0);
Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage( url, column, row): Promise<boolean>
Parameters
ParameterType
urlstring
columnnumber
rownumber
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage( url, column, row, offsetX, offsetY): Promise<boolean>
Parameters
ParameterType
urlstring
columnnumber
rownumber
offsetXnumber
offsetYnumber
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage(url): Promise<boolean>
Parameters
ParameterType
urlIFBlobSource
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage( url, column, row): Promise<boolean>
Parameters
ParameterType
urlIFBlobSource
columnnumber
rownumber
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage( url, column, row, offsetX, offsetY): Promise<boolean>
Parameters
ParameterType
urlIFBlobSource
columnnumber
rownumber
offsetXnumber
offsetYnumber
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage

Call Signature

insertImage( url, column, row, offsetX, offsetY): Promise<boolean>
Parameters
ParameterType
urlstring | IFBlobSource
columnnumber
rownumber
offsetXnumber
offsetYnumber
Returns

Promise<boolean>

Inherited from

IFWorksheetLegacy.insertImage


insertImages()

insertImages(sheetImages): FWorksheet

Insert images to the sheet

Parameters

ParameterTypeDescription
sheetImagesISheetImage[]The images to insert

Returns

FWorksheet

true if the image is inserted successfully

Example

const activeSpreadsheet = univerAPI.getActiveWorkbook(); const activeSheet = activeSpreadsheet.getActiveSheet(); const imageBuilder = activeSheet.newOverGridImage(); const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(500).setHeight(300).build(); activeSheet.insertImages([param]); const image = activeSheet.getImageById(param.drawingId); console.log(image); setTimeout(async ()=>{ const builder = image.toBuilder(); const param = await builder.setHeight(50).setWidth(100).build(); activeSheet.updateImages([param]); }, 4000); #### Inherited from [`IFWorksheetLegacy`](../interfaces/IFWorksheetLegacy.md).[`insertImages`](../interfaces/IFWorksheetLegacy.md#insertimages) *** ### insertRowAfter() ```ts insertRowAfter(afterPosition): FWorksheet

Inserts a row after the given row position.

Parameters

ParameterTypeDescription
afterPositionnumberThe row after which the new row should be added, starting at 0 for the first row.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Insert 3 rows at row index 2 (before the third row) sheet.insertRowAfter(2); // Insert 1 row at row index 0 (before the first row) sheet.insertRowAfter(0);

insertRowBefore()

insertRowBefore(beforePosition): FWorksheet

Inserts a row before the given row position.

Parameters

ParameterTypeDescription
beforePositionnumberThe row before which the new row should be added, starting at 0 for the first row.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Insert 3 rows at row index 2 (before the third row) sheet.insertRowBefore(2); // Insert 1 row at row index 0 (before the first row) sheet.insertRowBefore(0);

insertRows()

insertRows(rowIndex, numRows?): FWorksheet

Inserts one or more consecutive blank rows in a sheet starting at the specified location.

Parameters

ParameterTypeDescription
rowIndexnumberThe index indicating where to insert a row, starting at 0 for the first row.
numRows?numberThe number of rows to insert.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Insert 3 rows at row index 2 (before the third row) sheet.insertRows(2, 3); // Insert 1 row at row index 0 (before the first row) sheet.insertRows(0);

insertRowsAfter()

insertRowsAfter(afterPosition, howMany): FWorksheet

Inserts a number of rows after the given row position.

Parameters

ParameterTypeDescription
afterPositionnumberThe row after which the new rows should be added, starting at 0 for the first row.
howManynumberThe number of rows to insert.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Insert 3 rows at row index 2 (before the third row) sheet.insertRowsAfter(2, 3); // Insert 1 row at row index 0 (before the first row) sheet.insertRowsAfter(0);

insertRowsBefore()

insertRowsBefore(beforePosition, howMany): FWorksheet

Inserts a number of rows before the given row position.

Parameters

ParameterTypeDescription
beforePositionnumberThe row before which the new rows should be added, starting at 0 for the first row.
howManynumberThe number of rows to insert.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Insert 3 rows at row index 2 (before the third row) sheet.insertRowsBefore(2, 3); // Insert 1 row at row index 0 (before the first row) sheet.insertRowsBefore(0);

isSheetHidden()

isSheetHidden(): boolean

Returns true if the sheet is currently hidden.

Returns

boolean

True if the sheet is hidden; otherwise, false.


moveColumns()

moveColumns(columnSpec, destinationIndex): FWorksheet

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.

Parameters

ParameterTypeDescription
columnSpecFRangeA range spanning the columns that should be moved
destinationIndexnumberThe 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

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Move columns C, D, E to column index 2 (columns B, C, D) sheet.moveColumns({ startColumn: 2, endColumn: 4 }, 1); // Move column A to column index 0 (column A) sheet.moveColumns({ startColumn: 0, endColumn: 0 }, 0);

moveConditionalFormattingRule()

moveConditionalFormattingRule( cfId, toCfId, type?): FWorksheet

Modify the priority of the conditional format

Parameters

ParameterTypeDescription
cfIdstringRules that need to be moved
toCfIdstringTarget rule
type?IAnchorAfter the default move to the destination rule, if type = before moves to the front, the default value is after

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Memberof

FWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rules = worksheet?.getConditionalFormattingRules()!; const rule = rules[2]; const targetRule = rules[0]; worksheet?.moveConditionalFormattingRule(rule.cfId, targetRule.cfId, 'before');

moveRows()

moveRows(rowSpec, destinationIndex): FWorksheet

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.

Parameters

ParameterTypeDescription
rowSpecFRangeA range spanning the rows that should be moved.
destinationIndexnumberThe 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

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Move 3 rows at row index 2 (rows 3-5) to row index 0 sheet.moveRows(rowSpec, 0); // Move 1 row at row index 0 (first row) to row index 2 sheet.moveRows(rowSpec, 2);

newChart()

newChart(fChart?): FChartBuilderBase

Returns a builder to create a new chart for this sheet.The builder will not automatically create the chart. You must call build() on the returned builder to create the chart by calling insertChart(chartBuilder).

Parameters

ParameterTypeDescription
fChart?FChartThe chart to update.

Returns

FChartBuilderBase

  • a new chart builder

Description

If the fChart is provided, the builder will be initialized with the existing chart’s data.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); const chartBuilder = fSheet.newChart(); const chartInfo = chartBuilder.addRange('A1:B8') .setChartType(ChartTypeBits.Column) .setPosition(1, 1, 0, 0) .setWidth(600) .setHeight(400) .build(); fSheet.insertChart(chartInfo);

newConditionalFormattingRule()

newConditionalFormattingRule(): FConditionalFormattingBuilder

Creates a constructor for conditional formatting

Returns

FConditionalFormattingBuilder

Examples

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rule = worksheet?.createConditionalFormattingRule() .whenCellNotEmpty() .setRanges([{ startRow: 0, endRow: 100, startColumn: 0, endColumn: 100 }]) .setItalic(true) .setItalic(true) .setBackground('red') .setFontColor('green') .build();

Memberof

IFWorksheetConditionalFormattingMixin


newOverGridImage()

newOverGridImage(): FOverGridImageBuilder

Create a new over grid image builder.

Returns

FOverGridImageBuilder

The builder

Example

// create a new over grid image builder. const builder = univerAPI.newOverGridImage();

Inherited from

IFWorksheetLegacy.newOverGridImage


onBeforeCellDataChange()

onBeforeCellDataChange(callback): IDisposable

Parameters

ParameterType
callback(cellValue) => void

Returns

IDisposable

Deprecated

use univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback) instead


onCellDataChange()

onCellDataChange(callback): IDisposable

Parameters

ParameterType
callback(cellValue) => void

Returns

IDisposable

Deprecated

use univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback) instead


onImageChanged()

onImageChanged(callback): IDisposable

Hook when a image is changed.

Parameters

ParameterTypeDescription
callback(images) => voidThe callback function when a image is changed.

Returns

IDisposable

Inherited from

IFWorksheetLegacy.onImageChanged


onImageDeleted()

onImageDeleted(callback): IDisposable

Hook when a image is deleted.

Parameters

ParameterTypeDescription
callback(images) => voidThe callback function when a image is deleted.

Returns

IDisposable

Inherited from

IFWorksheetLegacy.onImageDeleted


onImageInserted()

onImageInserted(callback): IDisposable

Hook when a image is inserted.

Parameters

ParameterTypeDescription
callback(images) => voidThe callback function when a image is inserted.

Returns

IDisposable

Inherited from

IFWorksheetLegacy.onImageInserted


onScroll()

onScroll(callback): IDisposable

Parameters

ParameterType
callback(params) => void

Returns

IDisposable

Deprecated

use univerAPI.addEvent(univerAPI.Event.Scroll, () => {}) instead


refreshCanvas()

refreshCanvas(): FWorksheet

Refresh the canvas.

Returns

FWorksheet


registerChartTheme()

registerChartTheme(themeName, theme): void

Univer chart is base on echarts, you can register your own theme by echart theme builder.

Parameters

ParameterTypeDescription
themeNamestringThe name of the theme.
themeIEchartThemeThe theme object.

Returns

void

Description

The theme object should be a valid echarts theme object.The online builder is available at https://echarts.apache.org/zh/theme-builder.html

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); // register your theme const theme = {}; // your theme object fSheet.registerChartTheme('myTheme', theme); // use your theme for chart const chartBuilder = fSheet.newChart().asLineChart(); chartBuilder.setTheme('myTheme'); const chartInfo = chartBuilder.addRange('A1:B8').build(); fSheet.insertChart(chartInfo);

removeChart()

removeChart(chart): Promise<boolean>

Removes a chart from the parent sheet.

Parameters

ParameterTypeDescription
chartFChartThe chart to remove.

Returns

Promise<boolean>

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); const charts = fSheet.getCharts(); if (charts.length > 0){ fSheet.removeChart(charts[0]); }

scrollToCell()

scrollToCell(row, column): FWorksheet

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.

Parameters

ParameterTypeDescription
rownumberCell row index
columnnumberCell column index

Returns

FWorksheet

  • Current worksheet

Example

univerAPI.getActiveWorkbook().getActiveSheet().scrollToCell(1, 1);

setActiveRange()

setActiveRange(range): FWorksheet

Sets the active selection region for this sheet.

Parameters

ParameterTypeDescription
rangeFRangeThe range to set as the active selection

Returns

FWorksheet

This sheet, for chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setActiveRange(fWorkSheet.getRange('A1'));

setColumnAutoWidth()

setColumnAutoWidth(columnPosition, numColumn): FWorksheet

Set the given column width to fix-content.

Parameters

ParameterTypeDescription
columnPositionnumberColumn position
numColumnnumberNumber of columns

Returns

FWorksheet

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); fWorksheet.setColumnAutoWidth(0, 3);

setColumnCustom()

setColumnCustom(custom): FWorksheet

Set custom properties for given columns.

Parameters

ParameterTypeDescription
customIObjectArrayPrimitiveType<CustomData>The custom properties to set

Returns

FWorksheet

This worksheet instance for chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setColumnCustom({ 0: { key: 'value' } });

setColumnCustomMetadata()

setColumnCustomMetadata(index, custom): FWorksheet

Set custom metadata of column

Parameters

ParameterTypeDescription
indexnumbercolumn index
customCustomDatacustom metadata

Returns

FWorksheet

Current worksheet, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setColumnCustomMetadata(0, { key: 'value' });

setColumnDefaultStyle()

setColumnDefaultStyle(index, style): FWorksheet

Set the default style of the worksheet row

Parameters

ParameterTypeDescription
indexnumberThe row index
stylestring | Nullable<…>The style name or style data

Returns

FWorksheet

This sheet, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); fWorksheet.setRowDefaultStyle(0, 'default');

setColumnHeaderHeight()

setColumnHeaderHeight(height): FWorksheet

Set column height for column header.

Parameters

ParameterTypeDescription
heightnumber

Returns

FWorksheet

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.setColumnHeaderHeight(100);

setColumnWidth()

setColumnWidth(columnPosition, width): FWorksheet

Sets the width of the given column in pixels.

Parameters

ParameterTypeDescription
columnPositionnumberThe position of the given column to set
widthnumberThe width in pixels to set it to

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Set width of column B to 100 pixels sheet.setColumnWidth(1, 100);

setColumnWidths()

setColumnWidths( startColumn, numColumn, width): FWorksheet

Sets the width of the given columns in pixels.

Parameters

ParameterTypeDescription
startColumnnumberThe starting column position to change
numColumnnumberThe number of columns to change
widthnumberThe width in pixels to set it to

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Set width of columns B-D (index 1-3) to 100 pixels sheet.setColumnWidths(1, 3, 100);

setConditionalFormattingRule()

setConditionalFormattingRule(cfId, rule): FWorksheet

Set the conditional format according to cfId

Parameters

ParameterTypeDescription
cfIdstring
ruleIConditionFormattingRule

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Memberof

IFWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); const rules = worksheet?.getConditionalFormattingRules()!; const rule = rules[0]; worksheet?.setConditionalFormattingRule(rule.cfId, { ...rule, ranges: [] });

setCustomMetadata()

setCustomMetadata(custom): FWorksheet

Set custom metadata of worksheet

Parameters

ParameterTypeDescription
customCustomDatacustom metadata

Returns

FWorksheet

Example

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

setDefaultStyle()

setDefaultStyle(style): FWorksheet

Set the default style of the worksheet

Parameters

ParameterTypeDescription
stylestringThe style to set

Returns

FWorksheet

This worksheet instance for chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); fWorksheet.setDefaultStyle('default');

setFreeze()

setFreeze(freeze): FWorksheet

Sets the frozen state of the current sheet.

Parameters

ParameterTypeDescription
freezeIFreezethe 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

FWorksheet

This worksheet instance for chaining

Deprecated

use setFrozenRows and setFrozenColumns instead.

Example

const sheet = workbook.getActiveSheet(); // Freeze first 3 rows and 2 columns sheet.setFreeze({ startRow: 3, startColumn: 2, xSplit: 2, ySplit: 3 });

setFrozenColumns()

Call Signature

setFrozenColumns(columns): FWorksheet

Set the number of frozen columns.

Parameters
ParameterTypeDescription
columnsnumberThe number of columns to freeze. To unfreeze all columns, set this value to 0.
Returns

FWorksheet

This FWorksheet instance.

Example
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // freeze the first 3 columns. fWorkSheet.setFrozenColumns(3);

Call Signature

setFrozenColumns(startColumn, endColumn): FWorksheet

Set freeze column, then the range from startColumn to endColumn will be fixed. e.g. setFrozenColumns(0, 2) will fix the column range from 0 to 2. e.g. setFrozenColumns(2, 3) will fix the column range from 2 to 3, And column from 0 to 1 will be invisible.

Parameters
ParameterTypeDescription
startColumnnumberThe start column of the range to freeze
endColumnnumberThe end column of the range to freeze
Returns

FWorksheet

This FWorksheet instance.

Example
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // freeze the first too columns. fWorkSheet.setFrozenColumns(0, 2);

setFrozenRows()

Call Signature

setFrozenRows(rows): FWorksheet

Set the number of frozen rows.

Parameters
ParameterTypeDescription
rowsnumberThe number of rows to freeze. To unfreeze all rows, set this value to 0.
Returns

FWorksheet

This FWorksheet instance.

Example
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // freeze the first 3 rows. fWorkSheet.setFrozenRows(3);

Call Signature

setFrozenRows(startRow, endRow): FWorksheet

Set freeze row, then the range from startRow to endRow will be fixed. e.g. setFrozenRows(0, 2) will fix the row range from 0 to 2. e.g. setFrozenRows(2, 3) will fix the row range from 2 to 3, And row from 0 to 1 will be invisible.

Parameters
ParameterTypeDescription
startRownumberThe start row of the range to freeze
endRownumberThe end row of the range to freeze
Returns

FWorksheet

This FWorksheet instance.

Example
const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // freeze the first too rows. fWorkSheet.setFrozenRows(0, 2);

setGridLinesColor()

setGridLinesColor(color): FWorksheet

Set the color of the gridlines in the sheet.

Parameters

ParameterTypeDescription
colorstringThe color to set for the gridlines.Undefined or null to reset to the default color.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // set the gridlines color to red fWorkSheet.setGridLinesColor('#ff0000');

setHiddenGridlines()

setHiddenGridlines(hidden): FWorksheet

Hides or reveals the sheet gridlines.

Parameters

ParameterTypeDescription
hiddenbooleanIf true, hide gridlines in this sheet; otherwise show the gridlines.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // hide the gridlines fWorkSheet.setHiddenGridlines(true);

setName()

setName(name): FWorksheet

Sets the sheet name.

Parameters

ParameterTypeDescription
namestringThe new name for the sheet.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // set the sheet name to 'Sheet1' fWorkSheet.setName('Sheet1');

setRowAutoHeight()

setRowAutoHeight(startRow, numRows): FWorksheet

Sets the height of the given rows to auto.

Parameters

ParameterTypeDescription
startRownumberThe starting row position to change
numRowsnumberThe number of rows to change

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); sheet.setRowAutoHeight(1, 10);

setRowCustom()

setRowCustom(custom): FWorksheet

Set custom properties for given rows.

Parameters

ParameterTypeDescription
customIObjectArrayPrimitiveType<CustomData>The custom properties to set

Returns

FWorksheet

This worksheet instance for chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setRowCustom({ key: 'value' });

setRowCustomMetadata()

setRowCustomMetadata(index, custom): FWorksheet

Set custom metadata of row

Parameters

ParameterTypeDescription
indexnumberrow index
customCustomDatacustom metadata

Returns

FWorksheet

Current worksheet, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); fWorkSheet.setRowCustomMetadata(0, { key: 'value' });

setRowDefaultStyle()

setRowDefaultStyle(index, style): FWorksheet

Set the default style of the worksheet column

Parameters

ParameterTypeDescription
indexnumberThe column index
stylestring | Nullable<…>The style name or style data

Returns

FWorksheet

This sheet, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); fWorksheet.setColumnDefaultStyle(0, 'default');

setRowHeaderWidth()

setRowHeaderWidth(width): FWorksheet

Set column height for column header.

Parameters

ParameterTypeDescription
widthnumber

Returns

FWorksheet

Example

const sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.setRowHeaderWidth(100);

setRowHeight()

setRowHeight(rowPosition, height): FWorksheet

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

Parameters

ParameterTypeDescription
rowPositionnumberThe row position to change.
heightnumberThe height in pixels to set it to.

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); // Set the height of the second row to 30 pixels sheet.setRowHeight(1, 30); // Set the height of the first row to 20 pixels sheet.setRowHeight(0, 20);

setRowHeights()

setRowHeights( startRow, numRows, height): FWorksheet

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

Parameters

ParameterTypeDescription
startRownumberThe starting row position to change
numRowsnumberThe number of rows to change
heightnumberThe height in pixels to set it to

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); sheet.setRowHeights(1, 10, 30);

setRowHeightsForced()

setRowHeightsForced( startRow, numRows, height): FWorksheet

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.

Parameters

ParameterTypeDescription
startRownumberThe starting row position to change
numRowsnumberThe number of rows to change
heightnumberThe height in pixels to set it to

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); sheet.setRowHeightsForced(1, 10, 30);

setTabColor()

setTabColor(color): FWorksheet

Sets the sheet tab color.

Parameters

ParameterTypeDescription
colorstringA color code in CSS notation (like ‘#ffffff’ or ‘white’), or null to reset the tab color.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheet = fWorkbook.getActiveSheet(); // set the tab color to red fWorkSheet.setTabColor('#ff0000');

showColumns()

showColumns(columnIndex, numColumn?): FWorksheet

Show one or more consecutive columns starting at the given index. Use 0-index for this method

Parameters

ParameterTypeDescription
columnIndexnumberThe starting index of the columns to unhide
numColumn?numberThe number of columns to unhide

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Unhide columns C, D, E sheet.unhideColumns(2, 3); // Unhide column A sheet.unhideColumns(0, 1);

showRows()

showRows(rowIndex, numRow?): FWorksheet

Scrolling sheet to make specific rows visible.

Parameters

ParameterTypeDescription
rowIndexnumberThe starting index of the rows
numRow?numberThe number of rows

Returns

FWorksheet

This worksheet instance for chaining

Example

const sheet = workbook.getActiveSheet(); // Show 3 rows starting from row index 1 (rows 2-4) sheet.showRows(1); // Show single row at index 0 (first row) sheet.showRows(0);

showSheet()

showSheet(): FWorksheet

Shows this sheet. Has no effect if the sheet is already visible.

Returns

FWorksheet

Returns the current worksheet instance for method chaining

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorkSheets = fWorkbook.getSheets(); // show the last sheet fWorkSheets[fWorkSheets.length - 1].showSheet();

sort()

sort(colIndex, asc?): FWorksheet

Sort the worksheet by the specified column.

Parameters

ParameterTypeDescription
colIndexnumberThe column index to sort by. which starts from 1.
asc?booleanThe sort order. true for ascending, false for descending.

Returns

FWorksheet

The worksheet itself for chaining.

Example

const activeSpreadsheet = univerAPI.getActiveWorkbook(); const activeSheet = activeSpreadsheet.getActiveSheet(); activeSheet.sort(1); // Sorts the worksheet by the first column in ascending order. activeSheet.sort(1, false); // Sorts the worksheet by the first column in descending order.

unComposeSparkline()

unComposeSparkline(ranges): void

Parameters

ParameterTypeDescription
rangesIRange[]Current selection

Returns

void

Description

Split the sparkline group within the current selection

Example

// Continuing from the `composeSparkline` demo const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); // There will only be one sparkline here const allSparklineBeforeUnCompose = worksheet.getAllSubSparkline(); worksheet.unComposeSparkline([{ startRow: 9, endRow: 9, startColumn: 0, endColumn: 1 }]); // After unCompose, there will be two sparklines here const allSparklineAfterUnCompose = worksheet.getAllSubSparkline(); console.log('debugger', allSparklineBeforeUnCompose, allSparklineAfterUnCompose);

unhideColumn()

unhideColumn(column): FWorksheet

Show the column in the given range.

Parameters

ParameterTypeDescription
columnFRangeThe range to unhide, if hidden

Returns

FWorksheet

This sheet, for chaining

Example

const sheet = workbook.getActiveSheet(); // Unhide columns C, D, E sheet.unhideColumn({ startColumn: 2, endColumn: 4 }); // Unhide column A sheet.unhideColumn({ startColumn: 0, endColumn: 0 });

unhideRow()

unhideRow(row): FWorksheet

Make the row in the given range visible.

Parameters

ParameterTypeDescription
rowFRangeThe range to unhide, if hidden.

Returns

FWorksheet

This sheet, for chaining.

Example

const sheet = workbook.getActiveSheet(); // Unhide 3 rows starting from row index 1 (rows 2-4) sheet.unhideRow(1); // Unhide single row at index 0 (first row) sheet.unhideRow(0);

updateChart()

updateChart(chartBuildInfo): void

Updates the chart on this sheet. This api can not update source range, please use FChart.updateRange.

Parameters

ParameterTypeDescription
chartBuildInfoIChartBuilderInfoThe chart builder info.

Returns

void

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fSheet = fWorkbook.getActiveSheet(); const chartInfo = fSheet.getCharts()[0]; if(chartInfo){ const chartBuilder = fSheet.newChart(chartInfo); const buildInfo =chartBuilder .setChartType(ChartTypeBits.Column) .setOptions('legend.position', 'right') .build(); fSheet.updateChart(buildInfo); }

updateImages()

updateImages(sheetImages): FWorksheet

Update images to the sheet

Parameters

ParameterTypeDescription
sheetImagesISheetImage[]The images to insert

Returns

FWorksheet

true if the image is inserted successfully

Example

const activeSpreadsheet = univerAPI.getActiveWorkbook(); const activeSheet = activeSpreadsheet.getActiveSheet(); const imageBuilder = activeSheet.newOverGridImage(); const param = await imageBuilder.setSource('https://avatars.githubusercontent.com/u/61444807?s=48&v=4').setColumn(5).setRow(5).setWidth(500).setHeight(300).build(); activeSheet.insertImages([param]); const image = activeSheet.getImageById(param.drawingId); console.log(image); setTimeout(async ()=>{ const builder = image.toBuilder(); const param = await builder.setHeight(50).setWidth(100).build(); activeSheet.updateImages([param]); }, 4000); #### Inherited from [`IFWorksheetLegacy`](../interfaces/IFWorksheetLegacy.md).[`updateImages`](../interfaces/IFWorksheetLegacy.md#updateimages) *** ### zoom() ```ts zoom(zoomRatio): FWorksheet

Set zoom ratio of the worksheet.

Parameters

ParameterTypeDescription
zoomRationumberThe zoom ratio to set.It should be in the range of 10 to 400.

Returns

FWorksheet

True if the command was successful, false otherwise.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); fWorksheet.zoom(200); const zoomRatio = fWorksheet.getZoom(); console.log(zoomRatio); // 200