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
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
This range, for chaining.
Description
If the range is not a single cell, an error will be thrown.
addComment()
addComment(content): Promise<boolean>
Parameters
Parameter | Type |
---|---|
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
Parameter | Type | Description |
---|---|---|
content | | IDocumentBody | FTheadCommentBuilder | The 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
Parameter | Type | Description |
---|---|---|
rule | IConditionFormattingRule |
Returns
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
Parameter | Type | Description |
---|---|---|
alert | Omit <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
Parameter | Type | Description |
---|---|---|
popup | IFCanvasPopup | The 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
Parameter | Type |
---|---|
popup | IFCanvasPopup |
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
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()
cancelHyperLink(id): boolean
Parameters
Parameter | Type |
---|---|
id | string |
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
{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
Parameter | Type |
---|---|
this | FRange |
Returns
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
Parameter | Type | Description |
---|---|---|
cfId | string |
Returns
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
Parameter | Type | Description |
---|---|---|
callback | (row , col , cell ) => void | the callback function to be called for each cell in the range |
Returns
void
generateHTML()
generateHTML(this): string
Generate HTML content for the range.
Parameters
Parameter | Type |
---|---|
this | FRange |
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
Parameter | Type | Description |
---|---|---|
withSheet ? | boolean | If 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
Parameter | Type |
---|---|
this | FRange |
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
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
Parameter | Type |
---|---|
this | FRange |
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
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
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
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
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
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()
getHyperLinks(): ICellHyperLink[]
Returns
Deprecated
use range.setRichTextValueForCell(range.getValue(true).getLinks())
instead
getRange()
getRange(): IRange
Gets the area where the statement is applied
Returns
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
The cell value
Example
univerAPI.getActiveWorkbook()
.getActiveSheet()
.getActiveRange()
.getValue()
Call Signature
getValue(includeRichText): any
Return first cell value in this range
Parameters
Parameter | Type | Description |
---|---|---|
includeRichText | true | Should 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
Parameter | Type | Description |
---|---|---|
includeRichText | true | Should 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
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
Parameter | Type | Description |
---|---|---|
style ? | any | style for highlight range. |
primary ? | any | primary 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
Parameter | Type | Description |
---|---|---|
defaultMerge ? | boolean | If true, only the value in the upper left cell is retained. |
Returns
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
Parameter | Type | Description |
---|---|---|
defaultMerge ? | boolean | If true, only the value in the upper left cell is retained. |
Returns
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
Parameter | Type | Description |
---|---|---|
defaultMerge ? | boolean | If true, only the value in the upper left cell is retained. |
Returns
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
Parameter | Type | Description |
---|---|---|
cfId | string | Rules that need to be moved |
toCfId | string | Target rule |
type ? | IAnchor | After the default move to the destination rule, if type = before moves to the front, the default value is after |
Returns
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
Parameter | Type | Description |
---|---|---|
themeName | string | The 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
Parameter | Type | Description |
---|---|---|
color | string | The background color |
Returns
This range, for chaining
Example
univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')
setBackgroundColor()
setBackgroundColor(color): FRange
Set background color for current range.
Parameters
Parameter | Type | Description |
---|---|---|
color | string | The background color |
Returns
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
Parameter | Type | Description |
---|---|---|
type | BorderType | The type of border to apply |
style | BorderStyleTypes | The border style |
color ? | string | Optional border color in CSS notation |
Returns
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
Parameter | Type | Description |
---|---|---|
cfId | string | |
rule | IConditionFormattingRule |
Returns
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
Parameter | Type | Description |
---|---|---|
data | CustomData | The custom meta data |
Returns
This range, for chaining
univerAPI.getActiveWorkbook()
.getActiveSheet()
.getActiveRange()
.setCustomMetaData({ key: 'value' });
setCustomMetaDatas()
setCustomMetaDatas(datas): FRange
Set custom meta data for current range.
Parameters
Parameter | Type | Description |
---|---|---|
datas | …[][] | The custom meta data |
Returns
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
Parameter | Type | Description |
---|---|---|
rule | Nullable <FDataValidation > | data validation rule, build by FUniver.newDataValidation |
Returns
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
Parameter | Type | Description |
---|---|---|
color | string | The 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
Parameter | Type | Description |
---|---|---|
fontFamily | string | The 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
Parameter | Type | Description |
---|---|---|
fontLine | FontLine | The 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
Parameter | Type | Description |
---|---|---|
size | number | A 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
Parameter | Type | Description |
---|---|---|
fontStyle | FontStyle | The 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
Parameter | Type | Description |
---|---|---|
fontWeight | FontWeight$1 | The 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
Parameter | Type | Description |
---|---|---|
alignment | FHorizontalAlignment | The horizontal alignment |
Returns
this range, for chaining
Example
univerAPI.getActiveWorkbook()
.getActiveSheet()
.getActiveRange()
.setHorizontalAlignment('left');
setHyperLink()
setHyperLink(url, label?): Promise<boolean>
Parameters
Parameter | Type |
---|---|
url | string |
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
Parameter | Type | Description |
---|---|---|
pattern | string | number format pattern. |
Returns
FRange
setRichTextValueForCell()
setRichTextValueForCell(value): FRange
Set the rich text value for the cell at the start of this range.
Parameters
Parameter | Type | Description |
---|---|---|
value | any | The rich text value |
Returns
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
Parameter | Type | Description |
---|---|---|
values | …[][] | The rich text value |
Returns
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
Parameter | Type | Description |
---|---|---|
value | | ICellData | CellValue | The 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
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
Parameter | Type | Description |
---|---|---|
value | | ICellData | CellValue | The 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
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
Parameter | Type | Description |
---|---|---|
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
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
Parameter | Type | Description |
---|---|---|
alignment | FVerticalAlignment | The vertical alignment |
Returns
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
Parameter | Type | Description |
---|---|---|
isWrapEnabled | boolean | Whether to enable wrap |
Returns
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
Parameter | Type | Description |
---|---|---|
strategy | WrapStrategy | The text wrapping strategy |
Returns
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
Parameter | Type | Description |
---|---|---|
column | SortColumnSpec | …[] | The column index with order or an array of column indexes with order. The column index starts from 1. |
Returns
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
Parameter | Type | Description |
---|---|---|
treatMultipleDelimitersAsOne ? | boolean | Whether 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
Parameter | Type | Description |
---|---|---|
treatMultipleDelimitersAsOne ? | boolean | Whether to treat multiple continuous delimiters as one. The default value is false. |
delimiter ? | SplitDelimiterEnum | The 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()
updateHyperLink(
id,
url,
label?): Promise<boolean>
Parameters
Parameter | Type |
---|---|
id | string |
url | string |
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
Parameter | Type | Description |
---|---|---|
themeName | string | The 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');