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