Skip to Content
ClassesFRange

Class: FRange

Represents a range of cells in a sheet. You can call methods on this Facade API object to read contents or manipulate the range.

Extends

  • FBaseInitialable.IFRangeFilter.IFRangeCommentMixin.IFRangeSheetsNumfmtMixin.IFRangeDataValidationMixin.IFRangeHyperlinkMixin.IFRangeConditionalFormattingMixin.IFRangeSort.IFRangeSheetsUIMixin.IFRangePrint

Methods

activate()

activate(): FRange

Sets the specified range as the active range, with the top left cell in the range as the current cell.

Returns

FRange

This range, for chaining.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); fRange.activate(); // the active cell will be A1

activateAsCurrentCell()

activateAsCurrentCell(): FRange

Sets the specified cell as the current cell. If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell. If the specified cell is not part of an existing range, then a new range is created with the cell as the active range and the current cell.

Returns

FRange

This range, for chaining.

Description

If the range is not a single cell, an error will be thrown.


addComment()

addComment(content): Promise<boolean>

Parameters

ParameterType
content| IDocumentBody | FTheadCommentBuilder

Returns

Promise<boolean>

Deprecated

use addCommentAsync as instead.


addCommentAsync()

addCommentAsync(content): Promise<boolean>

Add a comment to the start cell in the current range.

Parameters

ParameterTypeDescription
content| IDocumentBody | FTheadCommentBuilderThe content of the comment.

Returns

Promise<boolean>

Whether the comment is added successfully.

Example

const range = univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange(); const comment = univerAPI.newTheadComment() .setContent(univerAPI.newRichText().insertText('hello zhangsan')); const success = await range.addCommentAsync(comment);

addConditionalFormattingRule()

addConditionalFormattingRule(rule): FRange

Add a new conditional format

Parameters

ParameterTypeDescription
ruleIConditionFormattingRule

Returns

FRange

Returns the current range instance for method chaining

Memberof

IFRangeConditionalFormattingMixin


attachAlertPopup()

attachAlertPopup(alert): IDisposable

Attach an alert popup to the start cell of current range.

Parameters

ParameterTypeDescription
alertOmit<ICellAlert, "location">The alert to attach

Returns

IDisposable

The disposable object to detach the alert.

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); let range = sheet.getRange(2, 2, 3, 3); range.attachAlertPopup({ message: 'This is an alert', type: 'warning' });

attachPopup()

attachPopup(popup): any

Attach a popup to the start cell of current range. If current worksheet is not active, the popup will not be shown. Be careful to manager the detach disposable object, if not dispose correctly, it might memory leaks.

Parameters

ParameterTypeDescription
popupIFCanvasPopupThe popup to attach

Returns

any

The disposable object to detach the popup, if the popup is not attached, return null.

Example

univerAPI.getComponentManager().register( 'myPopup', () => React.createElement('div', { style: { color: 'red', fontSize: '14px' } }, 'Custom Popup') ); let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); let range = sheet.getRange(2, 2, 3, 3); univerAPI.getActiveWorkbook().setActiveRange(range); let disposable = range.attachPopup({ componentKey: 'myPopup' });

attachRangePopup()

attachRangePopup(popup): any

Attach a DOM popup to the current range.

Parameters

ParameterType
popupIFCanvasPopup

Returns

any

The disposable object to detach the alert.

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); let range = sheet.getRange(2, 2, 3, 3); univerAPI.getActiveWorkbook().setActiveRange(range); univerAPI.getComponentManager().register( 'myPopup', () => React.createElement('div', { style: { background: 'red', fontSize: '14px' } }, 'Custom Popup') ); let disposable = range.attachRangePopup({ componentKey: 'myPopup', direction: 'top' // 'vertical' | 'horizontal' | 'top' | 'right' | 'left' | 'bottom' | 'bottom-center' | 'top-center'; });

breakApart()

breakApart(): FRange

Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.

Returns

FRange

This range, for chaining

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const range = worksheet.getRange(0,0,2,2); const merge = range.merge(); const anchor = worksheet.getRange(0,0); const isPartOfMergeFirst = anchor.isPartOfMerge(); console.log('debugger' isPartOfMergeFirst) // true range.breakApart(); const isPartOfMergeSecond = anchor.isPartOfMerge(); console.log('debugger' isPartOfMergeSecond) // false

cancelHyperLink(id): boolean

Parameters

ParameterType
idstring

Returns

boolean

Deprecated

use range.setRichTextValueForCell(range.getValue(true).copy().cancelLink(id)) instead


clearComment()

clearComment(): Promise<boolean>

Returns

Promise<boolean>

Deprecated

use clearCommentAsync as instead.


clearCommentAsync()

clearCommentAsync(): Promise<boolean>

Clear the comment of the start cell in the current range.

Returns

Promise<boolean>

Whether the comment is cleared successfully.


clearComments()

clearComments(): Promise<boolean>

Returns

Promise<boolean>

Deprecated

use clearComments as instead.


clearCommentsAsync()

clearCommentsAsync(): Promise<boolean>

Clear all of the comments in the current range.

Returns

Promise<boolean>

Whether the comments are cleared successfully.

Example

const range = univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange(); const success = await range.clearCommentsAsync();

createConditionalFormattingRule()

createConditionalFormattingRule(): FConditionalFormattingBuilder

Creates a constructor for conditional formatting

Returns

FConditionalFormattingBuilder

{ConditionalFormatRuleBuilder}

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!);

createFilter()

createFilter(this): FFilter

Create a filter for the current range. If the worksheet already has a filter, this method would return null.

Parameters

ParameterType
thisFRange

Returns

FFilter

The interface class to handle the filter. If the worksheet already has a filter, this method would return null.

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const filter = worksheet.getRange('A1:D14').createFilter();

deleteConditionalFormattingRule()

deleteConditionalFormattingRule(cfId): FRange

Delete conditional format according to cfId

Parameters

ParameterTypeDescription
cfIdstring

Returns

FRange

Returns the current range instance for method chaining

Memberof

IFRangeConditionalFormattingMixin

Example

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

forEach()

forEach(callback): void

Iterate cells in this range. Merged cells will be respected.

Parameters

ParameterTypeDescription
callback(row, col, cell) => voidthe callback function to be called for each cell in the range

Returns

void


generateHTML()

generateHTML(this): string

Generate HTML content for the range.

Parameters

ParameterType
thisFRange

Returns

string

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.getRange(5, 7).generateHTML();

getA1Notation()

getA1Notation(withSheet?): string

Returns a string description of the range, in A1 notation.

Parameters

ParameterTypeDescription
withSheet?booleanIf true, the sheet name is included in the A1 notation.

Returns

string

The A1 notation of the range.

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:B2'); console.log(fRange.getA1Notation()); // A1:B2

getCell()

getCell(this): ICellWithCoord

Return this cell information, including whether it is merged and cell coordinates

Parameters

ParameterType
thisFRange

Returns

ICellWithCoord

cell location and coordinate.

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.getRange(5, 7).getCell();

getCellData()

getCellData(): ICellData

Return first cell model data in this range

Returns

ICellData

The cell model data

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellData()

getCellDataGrid()

getCellDataGrid(): ...[][]

Returns the cell data for the cells in the range.

Returns

…[][]

A two-dimensional array of cell data.

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellDataGrid()

getCellDatas()

getCellDatas(): ...[][]

Alias for getCellDataGrid.

Returns

…[][]

A two-dimensional array of cell data.

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellDatas()

getCellRect()

getCellRect(this): DOMRect

Returns the coordinates of this cell,does not include units

Parameters

ParameterType
thisFRange

Returns

DOMRect

coordinates of the cell, top, right, bottom, left

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); sheet.getRange(5, 7).getCellRect();

getCellStyle()

getCellStyle(): any

Return first cell style in this range

Returns

any

The cell style

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellStyle()

getCellStyleData()

getCellStyleData(): IStyleData

Return first cell style data in this range

Returns

IStyleData

The cell style data

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellStyleData()

getCellStyles()

getCellStyles(): ...[][]

Returns the cell styles for the cells in the range.

Returns

…[][]

A two-dimensional array of cell styles.

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCellStyles()

getColumn()

getColumn(): number

Gets the starting column number of the applied area

Returns

number

The starting column number of the area

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getColumn()

getComment()

getComment(): Nullable<FThreadComment>

Get the comment of the start cell in the current range.

Returns

Nullable<FThreadComment>

The comment of the start cell in the current range. If the cell does not have a comment, return null.

Example

const range = univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange(); const comment = range.getComment();

getComments()

getComments(): FThreadComment[]

Get the comments in the current range.

Returns

FThreadComment[]

The comments in the current range.

Example

const range = univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange(); const comments = range.getComments(); comments.forEach((comment) => { console.log(comment.getContent()); });

getConditionalFormattingRules()

getConditionalFormattingRules(): IConditionFormattingRule[]

Gets all the conditional formatting for the current range

Returns

IConditionFormattingRule[]

{IConditionFormattingRule[]}

Memberof

IFWorksheetConditionalFormattingMixin

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook?.getActiveSheet(); workbook?.setActiveRange(worksheet?.getRange(5, 5, 3, 3)!); const rules = univerAPI.getActiveWorkbook()?.getActiveRange()?.getConditionalFormattingRules();

getCustomMetaData()

getCustomMetaData(): CustomData

Returns the custom meta data for the cell at the start of this range.

Returns

CustomData

The custom meta data

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCustomMetaData()

getCustomMetaDatas()

getCustomMetaDatas(): ...[][]

Returns the custom meta data for the cells in the range.

Returns

…[][]

A two-dimensional array of custom meta data

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getCustomMetaDatas()

getDataValidation()

getDataValidation(): Nullable<FDataValidation>

Get first data validation rule in current range.

Returns

Nullable<FDataValidation>

data validation rule

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const dataValidation = worksheet.getActiveRange().getDataValidation();

getDataValidations()

getDataValidations(): FDataValidation[]

Get all data validation rules in current range.

Returns

FDataValidation[]

all data validation rules

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const dataValidations = worksheet.getActiveRange().getDataValidations();

getFilter()

getFilter(): FFilter

Get the filter for the current range’s worksheet. Normally, you can directly call getFilter on FWorksheet.

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.getRange('A1:D14').getFilter();

getFormulas()

getFormulas(): ...[][]

Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are empty strings for cells with no formula.

Returns

…[][]

A two-dimensional array of formulas in string format.

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getFormulas()

getHeight()

getHeight(): number

Gets the height of the applied area

Returns

number

The height of the area

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getHeight()

getHorizontalAlignment()

getHorizontalAlignment(): string

Returns the horizontal alignment for the top left cell of the range.

Returns

string

The horizontal alignment

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getHorizontalAlignment()

getHyperLinks(): ICellHyperLink[]

Returns

ICellHyperLink[]

Deprecated

use range.setRichTextValueForCell(range.getValue(true).getLinks()) instead


getRange()

getRange(): IRange

Gets the area where the statement is applied

Returns

IRange

The area where the statement is applied

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getRange()

getRow()

getRow(): number

Gets the starting row number of the applied area

Returns

number

The starting row number of the area

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getRow()

getScreenshot()

getScreenshot(): string | false

get screenshot of this range

Returns

string | false

Example

univerAPI.getActiveUniverSheet() .getActiveSheet() .getActiveRange() .getScreenshot();

getSheetId()

getSheetId(): string

Gets the ID of the worksheet

Returns

string

The ID of the worksheet

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getSheetId()

getSheetName()

getSheetName(): string

Gets the name of the worksheet

Returns

string

The name of the worksheet

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getSheetName()

getUnitId()

getUnitId(): string

Get the unit ID of the current workbook

Returns

string

The unit ID of the workbook

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getUnitId()

getUrl()

getUrl(): string

Get the url of this range.

Returns

string


getUsedThemeStyle()

getUsedThemeStyle(): string

Gets the theme style applied to the range.

Returns

string

The name of the theme style applied to the range or not exist.

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:E20'); fRange.useThemeStyle('default'); const themeStyle = fRange.getUsedThemeStyle(); console.log(themeStyle); // 'default'

getValidatorStatus()

getValidatorStatus(): Promise<...[]>

Get data validation validator status for current range.

Returns

Promise<…[]>

matrix of validator status

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const validatorStatus = worksheet.getActiveRange().getValidatorStatus();

getValue()

Call Signature

getValue(): CellValue

Return first cell value in this range

Returns

CellValue

The cell value

Example
univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getValue()

Call Signature

getValue(includeRichText): any

Return first cell value in this range

Parameters
ParameterTypeDescription
includeRichTexttrueShould the returns of this func to include rich text
Returns

any

The cell value

Example
univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getValue(true)

getValueAndRichTextValues()

getValueAndRichTextValues(): ...[][]

Returns the value and rich text value for the cells in the range.

Returns

…[][]

A two-dimensional array of value and rich text value

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getValueAndRichTextValues()

getValues()

Call Signature

getValues(): ...[][]

Returns the cell values for the cells in the range.

Returns

…[][]

A two-dimensional array of cell values.

Example
// Get plain values const values = range.getValues();

Call Signature

getValues(includeRichText): ...[][]

Returns the cell values for the cells in the range.

Parameters
ParameterTypeDescription
includeRichTexttrueShould the returns of this func to include rich text
Returns

…[][]

A two-dimensional array of cell values.

Example
// Get values with rich text if available const richTextValues = univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getValues(true)

getVerticalAlignment()

getVerticalAlignment(): string

Returns the vertical alignment for the top left cell of the range.

Returns

string

The vertical alignment

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getVerticalAlignment()

getWidth()

getWidth(): number

Gets the width of the applied area

Returns

number

The width of the area

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getWidth()

getWrap()

getWrap(): boolean

Returns true if the cell wrap is enabled

Returns

boolean

True if the cell wrap is enabled

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getWrap()

getWrapStrategy()

getWrapStrategy(): WrapStrategy

Returns the text wrapping strategy for the top left cell of the range.

Returns

WrapStrategy

The text wrapping strategy

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .getWrapStrategy()

highlight()

highlight(style?, primary?): IDisposable

Highlight the range with the specified style and primary cell.

Parameters

ParameterTypeDescription
style?anystyle for highlight range.
primary?anyprimary cell for highlight range.

Returns

IDisposable

Example

let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); let range = sheet.getRange(2, 2, 3, 3); range.highlight({ stroke: 'red' }, { startRow: 2, startColumn: 2 });

isMerged()

isMerged(): boolean

Return range whether this range is merged

Returns

boolean

if true is merged

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .isMerged()

isPartOfMerge()

isPartOfMerge(): boolean

Returns true if cells in the current range overlap a merged cell.

Returns

boolean

is overlap with a merged cell

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const range = worksheet.getRange(0,0,2,2); const merge = range.merge(); const anchor = worksheet.getRange(0,0); const isPartOfMerge = anchor.isPartOfMerge(); console.log('debugger, isPartOfMerge) // true

merge()

merge(defaultMerge?): FRange

Merge cells in a range into one merged cell

Parameters

ParameterTypeDescription
defaultMerge?booleanIf true, only the value in the upper left cell is retained.

Returns

FRange

This range, for chaining

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const range = worksheet.getRange(0, 0, 2, 2); const merge = range.merge(); const isMerged = merge.isMerged(); console.log('debugger', isMerged);

mergeAcross()

mergeAcross(defaultMerge?): FRange

Merges cells in a range horizontally.

Parameters

ParameterTypeDescription
defaultMerge?booleanIf true, only the value in the upper left cell is retained.

Returns

FRange

This range, for chaining

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const range = worksheet.getRange(2, 2, 2, 2); const merge = range.mergeAcross(); const allMerge = worksheet.getMergeData(); console.log(allMerge.length); // There will be two merged cells.

mergeVertically()

mergeVertically(defaultMerge?): FRange

Merges cells in a range vertically.

Parameters

ParameterTypeDescription
defaultMerge?booleanIf true, only the value in the upper left cell is retained.

Returns

FRange

This range, for chaining

Example

const workbook = univerAPI.getActiveWorkbook(); const worksheet = workbook.getActiveSheet(); const range = worksheet.getRange(4, 4, 2, 2); const merge = range.mergeVertically(); const allMerge = worksheet.getMergeData(); console.log(allMerge.length); // There will be two merged cells.

moveConditionalFormattingRule()

moveConditionalFormattingRule( cfId, toCfId, type?): FRange

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

FRange

Returns the current range instance for method chaining

Memberof

FRangeConditionalFormattingMixin

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');

removeThemeStyle()

removeThemeStyle(themeName): void

Remove the theme style for the range.

Parameters

ParameterTypeDescription
themeNamestringThe name of the theme style to remove.

Returns

void

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:E20'); fRange.removeThemeStyle('default');

setBackground()

setBackground(color): FRange

Set background color for current range.

Parameters

ParameterTypeDescription
colorstringThe background color

Returns

FRange

This range, for chaining

Example

univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')

setBackgroundColor()

setBackgroundColor(color): FRange

Set background color for current range.

Parameters

ParameterTypeDescription
colorstringThe background color

Returns

FRange

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setBackgroundColor('red')

setBorder()

setBorder( type, style, color?): FRange

Sets basic border properties for the current range.

Parameters

ParameterTypeDescription
typeBorderTypeThe type of border to apply
styleBorderStyleTypesThe border style
color?stringOptional border color in CSS notation

Returns

FRange

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');

setConditionalFormattingRule()

setConditionalFormattingRule(cfId, rule): FRange

Set the conditional format according to cfId

Parameters

ParameterTypeDescription
cfIdstring
ruleIConditionFormattingRule

Returns

FRange

Returns the current range instance for method chaining

Memberof

IFRangeConditionalFormattingMixin

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(data): FRange

Set custom meta data for first cell in current range.

Parameters

ParameterTypeDescription
dataCustomDataThe custom meta data

Returns

FRange

This range, for chaining

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setCustomMetaData({ key: 'value' });

setCustomMetaDatas()

setCustomMetaDatas(datas): FRange

Set custom meta data for current range.

Parameters

ParameterTypeDescription
datas…[][]The custom meta data

Returns

FRange

This range, for chaining

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setCustomMetaDatas([[{ key: 'value' }]]);

setDataValidation()

setDataValidation(rule): FRange

Set a data validation rule to current range. if rule is null, clear data validation rule.

Parameters

ParameterTypeDescription
ruleNullable<FDataValidation>data validation rule, build by FUniver.newDataValidation

Returns

FRange

current range

Example

const rule = FUniver.newDataValidation().requireValueInRange(range).build(); cell.setDataValidation(rule);

setFontColor()

setFontColor(color): this

Sets the font color in CSS notation (such as ‘#ffffff’ or ‘white’).

Parameters

ParameterTypeDescription
colorstringThe font color in CSS notation (such as ‘#ffffff’ or ‘white’); a null value resets the color.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontColor('#ff0000');

setFontFamily()

setFontFamily(fontFamily): this

Sets the font family, such as “Arial” or “Helvetica”.

Parameters

ParameterTypeDescription
fontFamilystringThe font family to set; a null value resets the font family.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontFamily('Arial');

setFontLine()

setFontLine(fontLine): this

Sets the font line style of the given range (‘underline’, ‘line-through’, or ‘none’).

Parameters

ParameterTypeDescription
fontLineFontLineThe font line style, either ‘underline’, ‘line-through’, or ‘none’; a null value resets the font line style.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontLine('underline');

setFontSize()

setFontSize(size): this

Sets the font size, with the size being the point size to use.

Parameters

ParameterTypeDescription
sizenumberA font size in point size. A null value resets the font size.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontSize(12);

setFontStyle()

setFontStyle(fontStyle): this

Sets the font style for the given range (‘italic’ or ‘normal’).

Parameters

ParameterTypeDescription
fontStyleFontStyleThe font style, either ‘italic’ or ‘normal’; a null value resets the font style.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontStyle('italic');

setFontWeight()

setFontWeight(fontWeight): this

Sets the font weight for the given range (normal/bold),

Parameters

ParameterTypeDescription
fontWeightFontWeight$1The font weight, either ‘normal’ or ‘bold’; a null value resets the font weight.

Returns

this

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setFontWeight('bold');

setHorizontalAlignment()

setHorizontalAlignment(alignment): FRange

Set the horizontal (left to right) alignment for the given range (left/center/right).

Parameters

ParameterTypeDescription
alignmentFHorizontalAlignmentThe horizontal alignment

Returns

FRange

this range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setHorizontalAlignment('left');

setHyperLink(url, label?): Promise<boolean>

Parameters

ParameterType
urlstring
label?string

Returns

Promise<boolean>

Deprecated

use range.setRichTextValueForCell(univerAPI.newRichText().insertLink(label, url)) instead


setNumberFormat()

setNumberFormat(pattern): FRange

Set the number format of the range.

Parameters

ParameterTypeDescription
patternstringnumber format pattern.

Returns

FRange

FRange


setRichTextValueForCell()

setRichTextValueForCell(value): FRange

Set the rich text value for the cell at the start of this range.

Parameters

ParameterTypeDescription
valueanyThe rich text value

Returns

FRange

The range

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setRichTextValueForCell(new RichTextValue().insertText('Hello'));

setRichTextValues()

setRichTextValues(values): FRange

Set the rich text value for the cells in the range.

Parameters

ParameterTypeDescription
values…[][]The rich text value

Returns

FRange

The range

Example

univerAPI .getActiveWorkbook() .getActiveSheet() .getActiveRange() .setRichTextValues([[new RichTextValue().insertText('Hello')]]);

setValue()

setValue(value): FRange

Set new value for current cell, first cell in this range.

Parameters

ParameterTypeDescription
value| ICellData | CellValueThe value can be a number, string, boolean, or standard cell format. If it begins with =, it is interpreted as a formula. The value is tiled to all cells in the range.

Returns

FRange

This range, for chaining

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setValue(1);

setValueForCell()

setValueForCell(value): FRange

Set new value for current cell, first cell in this range.

Parameters

ParameterTypeDescription
value| ICellData | CellValueThe value can be a number, string, boolean, or standard cell format. If it begins with =, it is interpreted as a formula. The value is tiled to all cells in the range.

Returns

FRange

This range, for chaining

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setValueForCell(1);

setValues()

setValues(value): FRange

Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with =, it is interpreted as a formula.

Parameters

ParameterTypeDescription
value| IObjectMatrixPrimitiveType<…> | …[] | IObjectMatrixPrimitiveType<…> | …[]The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats.

Returns

FRange

This range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setValues([[1, 2], [3, 4]]);

setVerticalAlignment()

setVerticalAlignment(alignment): FRange

Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).

Parameters

ParameterTypeDescription
alignmentFVerticalAlignmentThe vertical alignment

Returns

FRange

this range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setVerticalAlignment('top');

setWrap()

setWrap(isWrapEnabled): FRange

Set the cell wrap of the given range. Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.

Parameters

ParameterTypeDescription
isWrapEnabledbooleanWhether to enable wrap

Returns

FRange

this range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setWrap(true);

setWrapStrategy()

setWrapStrategy(strategy): FRange

Sets the text wrapping strategy for the cells in the range.

Parameters

ParameterTypeDescription
strategyWrapStrategyThe text wrapping strategy

Returns

FRange

this range, for chaining

Example

univerAPI.getActiveWorkbook() .getActiveSheet() .getActiveRange() .setWrapStrategy(WrapStrategy.WRAP);

sort()

sort(column): FRange

Sorts the cells in the given range, by column(s) and order specified.

Parameters

ParameterTypeDescription
columnSortColumnSpec | …[]The column index with order or an array of column indexes with order. The column index starts from 1.

Returns

FRange

The range itself for chaining.

Example

const activeSpreadsheet = univerAPI.getActiveWorkbook(); const activeSheet = activeSpreadsheet.getActiveSheet(); const range = activeSheet.getRange(0, 0, 10, 10); range.sort(1); // Sorts the range by the first column in ascending order. range.sort({ column: 1, ascending: false }); // Sorts the range by the first column in descending order. range.sort([{ column: 1, ascending: false }, 2]); // Sorts the range by the first column in descending order and the second column in ascending order.

splitTextToColumns()

Call Signature

splitTextToColumns(treatMultipleDelimitersAsOne?): void

Splits a column of text into multiple columns based on an auto-detected delimiter.

Parameters
ParameterTypeDescription
treatMultipleDelimitersAsOne?booleanWhether to treat multiple continuous delimiters as one. The default value is false.
Returns

void

Example
// A1:A3 has following values: // A | B | C // 1,2,3 | | // 4,,5,6 | | // After calling splitTextToColumns(true), the range will be: // A | B | C // 1 | 2 | 3 // 4 | 5 | 6 // After calling splitTextToColumns(false), the range will be: // A | B | C | D // 1 | 2 | 3 | // 4 | | 5 | 6

Call Signature

splitTextToColumns(treatMultipleDelimitersAsOne?, delimiter?): void

Splits a column of text into multiple columns based on a specified delimiter.

Parameters
ParameterTypeDescription
treatMultipleDelimitersAsOne?booleanWhether to treat multiple continuous delimiters as one. The default value is false.
delimiter?SplitDelimiterEnumThe delimiter to use to split the text. The default delimiter is Tab(1)、Comma(2)、Semicolon(4)、Space(8)、Custom(16).A delimiter like 6 (SplitDelimiterEnum.Comma
Returns

void


updateHyperLink( id, url, label?): Promise<boolean>

Parameters

ParameterType
idstring
urlstring
label?string

Returns

Promise<boolean>

Deprecated

use range.setRichTextValueForCell(range.getValue(true).copy().updateLink(id, url)) instead


useThemeStyle()

useThemeStyle(themeName): void

Set the theme style for the range.

Parameters

ParameterTypeDescription
themeNamestringThe name of the theme style to apply.If a undefined value is passed, the theme style will be removed if it exist.

Returns

void

Example

const fWorkbook = univerAPI.getActiveWorkbook(); const fWorksheet = fWorkbook.getActiveSheet(); const fRange = fWorksheet.getRange('A1:E20'); fRange.useThemeStyle('default');