Range
| Packages | @univerjs/sheets, @univerjs/sheets-thread-comment, @univerjs/sheets-conditional-formatting, @univerjs/sheets-ui, @univerjs/sheets-hyper-link, @univerjs/sheets-filter, @univerjs/sheets-note, @univerjs/sheets-data-validation, @univerjs/sheets-formula, @univerjs-labs/sheets-mcp, @univerjs/sheets-numfmt, @univerjs-pro/sheets-print, @univerjs-labs/sheets-node-screenshot, @univerjs/sheets-drawing-ui, @univerjs/sheets-sort |
|---|
Represents a range of cells in a sheet. You can call methods on this Facade API object to read contents or manipulate the range.
This class should not be instantiated directly. Use factory methods on
univerAPIinstead.
Overview
@univerjs/sheets
| Method | Description |
|---|---|
activate | Sets the specified range as the active range, with the top left cell in the range as the current cell |
activateAsCurrentCell | Sets the specified cell as the current cell |
autoFill | Fills the target range with data based on the data in the current range |
breakApart | Break all horizontally- or vertically-merged cells contained within the range list into individual cells again |
clear | Clears content and formatting information of the range |
clearContent | Clears content of the range, while preserving formatting information |
clearFormat | Clears formatting information of the range, while preserving contents |
deleteCells | Deletes this range of cells |
forEach | Iterate cells in this range |
getA1Notation | Returns a string description of the range, in A1 notation |
getBackground | Returns the background color of the top-left cell in the range |
getBackgrounds | Returns the background colors of the cells in the range |
getCellData | Return first cell model data in this range |
getCellDataGrid | Returns the cell data for the cells in the range |
getCellDatas | Alias for getCellDataGrid |
getCellStyle | Return first cell style in this range |
getCellStyleData | Return first cell style data in this range |
getCellStyles | Returns the cell styles for the cells in the range |
getColumn | Gets the starting column index of the range |
getCustomMetaData | Returns the custom meta data for the cell at the start of this range |
getCustomMetaDatas | Returns the custom meta data for the cells in the range |
getDataRegion | Returns a copy of the range expanded `Direction |
getDisplayValue | Returns the displayed value of the top-left cell in the range |
getDisplayValues | Returns a two-dimensional array of the range displayed values |
getFontFamily | Get the font family of the cell |
getFontSize | Get the font size of the cell |
getFormula | Returns the formula (A1 notation) of the top-left cell in the range, or an empty string if the cell is empty or doesn't contain a formula |
getFormulas | Returns the formulas (A1 notation) for the cells in the range |
getHeight | Gets the height of the applied area |
getHorizontalAlignment | Returns the horizontal alignment of the text (left/center/right) of the top-left cell in the range |
getHorizontalAlignments | Returns the horizontal alignments of the cells in the range |
getLastColumn | Gets the ending column index of the range |
getLastRow | Gets the ending row index of the range |
getRange | Gets the area where the statement is applied |
getRangePermission | Get the RangePermission instance for managing range-level permissions |
getRawValue | Returns the raw value of the top-left cell in the range |
getRawValues | Returns a two-dimensional array of the range raw values |
getRow | Gets the starting row index of the range |
getSheetId | Gets the ID of the worksheet |
getSheetName | Gets the name of the worksheet |
getUnitId | Get the unit ID of the current workbook |
getUsedThemeStyle | Gets the theme style applied to the range |
getValue | - |
getValueAndRichTextValues | Returns the value and rich text value for the cells in the range |
getValues | - |
getVerticalAlignment | Returns the vertical alignment (top/middle/bottom) of the top-left cell in the range |
getVerticalAlignments | Returns the vertical alignments of the cells in the range |
getWidth | Gets the width of the applied area |
getWrap | Gets whether text wrapping is enabled for top-left cell in the range |
getWraps | Gets whether text wrapping is enabled for cells in the range |
getWrapStrategy | Returns the text wrapping strategy for the top left cell of the range |
insertCells | Inserts empty cells into this range |
isBlank | Returns true if the range is totally blank |
isMerged | Return range whether this range is merged |
isPartOfMerge | Returns true if cells in the current range overlap a merged cell |
merge | Merge cells in a range into one merged cell |
mergeAcross | Merges cells in a range horizontally |
mergeVertically | Merges cells in a range vertically |
offset | Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height and width in cells |
removeThemeStyle | Remove the theme style for the range |
setBackground | Set background color for current range |
setBackgroundColor | Set background color for current range |
setBorder | Sets basic border properties for the current range |
setCustomMetaData | Set custom meta data for first cell in current range |
setCustomMetaDatas | Set custom meta data for current range |
setFontColor | Sets the font color in CSS notation (such as '#ffffff' or 'white') |
setFontFamily | Sets the font family, such as "Arial" or "Helvetica" |
setFontLine | Sets the font line style of the given range ('underline', 'line-through', or 'none') |
setFontSize | Sets the font size, with the size being the point size to use |
setFontStyle | Sets the font style for the given range ('italic' or 'normal') |
setFontWeight | Sets the font weight for the given range (normal/bold), |
setFormula | Updates the formula for this range |
setFormulas | Sets a rectangular grid of formulas (must match dimensions of this range) |
setHorizontalAlignment | Set the horizontal (left to right) alignment for the given range (left/center/right) |
setRichTextValueForCell | Set the rich text value for the cell at the start of this range |
setRichTextValues | Set the rich text value for the cells in the range |
setTextRotation | Set rotation for text in current range |
setValue | Sets the value of the range |
setValueForCell | Set new value for current cell, first cell in this range |
setValues | Sets a different value for each cell in the range |
setVerticalAlignment | Set the vertical (top to bottom) alignment for the given range (top/middle/bottom) |
setWrap | Set the cell wrap of the given range |
setWrapStrategy | Sets the text wrapping strategy for the cells in the range |
splitTextToColumns | Splits a column of text into multiple columns based on a custom specified delimiter |
useThemeStyle | Set the theme style for the range |
@univerjs/sheets-conditional-formatting
@univerjs/sheets-data-validation
| Method | Description |
|---|---|
getDataValidation | - |
getDataValidationErrorAsync | - |
getDataValidations | - |
getValidatorStatus | - |
setDataValidation | - |
@univerjs/sheets-drawing-ui
| Method | Description |
|---|---|
insertCellImageAsync | - |
saveCellImagesAsync | - |
@univerjs/sheets-filter
| Method | Description |
|---|---|
createFilter | - |
getFilter | Get the filter for the current range's worksheet |
@univerjs/sheets-formula
| Method | Description |
|---|---|
getFormulaError | - |
@univerjs/sheets-hyper-link
| Method | Description |
|---|---|
cancelHyperLink | - |
getHyperLinks | - |
getUrl | - |
setHyperLink | - |
updateHyperLink | - |
@univerjs/sheets-note
| Method | Description |
|---|---|
createOrUpdateNote | - |
deleteNote | - |
getNote | - |
@univerjs/sheets-numfmt
| Method | Description |
|---|---|
getNumberFormat | - |
getNumberFormats | - |
setNumberFormat | - |
setNumberFormats | - |
@univerjs/sheets-sort
| Method | Description |
|---|---|
sort | - |
@univerjs/sheets-thread-comment
| Method | Description |
|---|---|
addComment | - |
addCommentAsync | - |
clearComment | - |
clearCommentAsync | - |
clearComments | - |
clearCommentsAsync | - |
getComment | - |
getComments | - |
@univerjs/sheets-ui
| Method | Description |
|---|---|
attachAlertPopup | - |
attachPopup | - |
attachRangePopup | attachDOMPopup |
generateHTML | - |
getCell | - |
getCellRect | - |
highlight | - |
showDropdown | - |
@univerjs-pro/sheets-print
| Method | Description |
|---|---|
getScreenshot | - |
@univerjs-labs/sheets-mcp
| Method | Description |
|---|---|
getFormulaUsages | - |
getFormulaUsagesAsA1 | - |
getRectArea | - |
getRectAreaData | - |
getSizeUsages | - |
getSizeUsagesAsA1 | - |
getStyleUsages | - |
getStyleUsagesAsA1 | - |
@univerjs-labs/sheets-node-screenshot
| Method | Description |
|---|---|
getScreenshotOnNode | - |
APIs
Value & Formula
getCellData
Return first cell model data in this range
Signature
getCellData(): ICellData | nullReturns
ICellData— The cell model data
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellData());@univerjs/sheets
getCellDataGrid
Returns the cell data for the cells in the range.
Signature
getCellDataGrid(): Nullable<ICellData>[][]Returns
Nullable<ICellData>[][]— A two-dimensional array of cell data.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellDataGrid());@univerjs/sheets
getCellDatas
Alias for getCellDataGrid.
Signature
getCellDatas(): Nullable<ICellData>[][]Returns
Nullable<ICellData>[][]— A two-dimensional array of cell data.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellDatas());@univerjs/sheets
getCellStyleData
Return first cell style data in this range. Please note that if there are row styles, col styles and (or)
worksheet style, they will be merged into the cell style. You can use type to specify the type of the style to get.
Signature
getCellStyleData(type: GetStyleType = 'row'): IStyleData | nullParameters
typeGetStyleType(optional) — No description
Returns
IStyleData— The cell style data
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellStyleData());@univerjs/sheets
getCustomMetaData
Returns the custom meta data for the cell at the start of this range.
Signature
getCustomMetaData(): CustomData | nullReturns
CustomData— The custom meta data
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCustomMetaData());@univerjs/sheets
getCustomMetaDatas
Returns the custom meta data for the cells in the range.
Signature
getCustomMetaDatas(): Nullable<CustomData>[][]Returns
Nullable<CustomData>[][]— A two-dimensional array of custom meta data
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCustomMetaDatas());@univerjs/sheets
getDataRegion
Returns a copy of the range expanded Direction.UP and Direction.DOWN if the specified dimension is Dimension.ROWS, or Direction.NEXT and Direction.PREVIOUS if the dimension is Dimension.COLUMNS.
The expansion of the range is based on detecting data next to the range that is organized like a table.
The expanded range covers all adjacent cells with data in them along the specified dimension including the table boundaries.
If the original range is surrounded by empty cells along the specified dimension, the range itself is returned.
Signature
getDataRegion(dimension?: Dimension): FRangeParameters
dimensionDimension(optional) — No description
Returns
FRange— The range's data region or a range covering each column or each row spanned by the original range.
Examples
// Assume the active sheet is a new sheet with no data.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Set the range A1:D4 with some values, the range A1:D4 will be:
// | | |
// | | 100 |
// | 100 | | 100
// | | 100 |
fWorksheet.getRange('C2').setValue(100);
fWorksheet.getRange('B3').setValue(100);
fWorksheet.getRange('D3').setValue(100);
fWorksheet.getRange('C4').setValue(100);
// Get C3 data region along the rows dimension, the range will be C2:D4
const range = fWorksheet.getRange('C3').getDataRegion(univerAPI.Enum.Dimension.ROWS);
console.log(range.getA1Notation()); // C2:C4
// Get C3 data region along the columns dimension, the range will be B3:D3
const range2 = fWorksheet.getRange('C3').getDataRegion(univerAPI.Enum.Dimension.COLUMNS);
console.log(range2.getA1Notation()); // B3:D3
// Get C3 data region along the both dimension, the range will be B2:D4
const range3 = fWorksheet.getRange('C3').getDataRegion();
console.log(range3.getA1Notation()); // B2:D4@univerjs/sheets
getDataValidation
Signature
getDataValidation(): Nullable<FDataValidation>Returns
Nullable<FDataValidation>— See signature above.
@univerjs/sheets-data-validation
getDataValidationErrorAsync
Signature
async getDataValidationErrorAsync(): Promise<IDataValidationError[]>Returns
Promise<IDataValidationError[]>— See signature above.
@univerjs/sheets-data-validation
getDataValidations
Signature
getDataValidations(): FDataValidation[]Returns
FDataValidation[]— See signature above.
@univerjs/sheets-data-validation
getDisplayValue
Returns the displayed value of the top-left cell in the range. The value is a String. Empty cells return an empty string.
Signature
getDisplayValue(): stringReturns
string— The displayed value of the cell. Returns an empty string if the cell is empty.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValueForCell({
v: 0.2,
s: {
n: {
pattern: '0%',
},
},
});
console.log(fRange.getDisplayValue()); // 20%@univerjs/sheets
getDisplayValues
Returns a two-dimensional array of the range displayed values. Empty cells return an empty string.
Signature
getDisplayValues(): string[][]Returns
string[][]— A two-dimensional array of values.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValues([
[
{
v: 0.2,
s: {
n: {
pattern: '0%',
},
},
},
{
v: 45658,
s: {
n: {
pattern: 'yyyy-mm-dd',
},
},
}
],
[
{
v: 1234.567,
s: {
n: {
pattern: '#,##0.00',
}
}
},
null,
],
]);
console.log(fRange.getDisplayValues()); // [['20%', '2025-01-01'], ['1,234.57', '']]@univerjs/sheets
getFormula
Returns the formula (A1 notation) of the top-left cell in the range, or an empty string if the cell is empty or doesn't contain a formula.
Signature
getFormula(): stringReturns
string— The formula for the cell.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getFormula());@univerjs/sheets
getFormulaError
Signature
getFormulaError(): ISheetFormulaError[]Returns
ISheetFormulaError[]— See signature above.
@univerjs/sheets-formula
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.
Signature
getFormulas(): string[][]Returns
string[][]— A two-dimensional array of formulas in string format.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getFormulas());@univerjs/sheets
getFormulaUsages
Signature
async getFormulaUsages(): Promise<IFormulaUsage[]>Returns
Promise<IFormulaUsage[]>— See signature above.
@univerjs-labs/sheets-mcp
getFormulaUsagesAsA1
Signature
async getFormulaUsagesAsA1(): Promise<IFormulaUsageAsA1[]>Returns
Promise<IFormulaUsageAsA1[]>— See signature above.
@univerjs-labs/sheets-mcp
getRawValue
Returns the raw value of the top-left cell in the range. Empty cells return null.
Signature
getRawValue(): Nullable<CellValue>Returns
Nullable<CellValue>— The raw value of the cell. Returnsnullif the cell is empty.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValueForCell({
v: 0.2,
s: {
n: {
pattern: '0%',
},
},
});
console.log(fRange.getRawValue()); // 0.2@univerjs/sheets
getRawValues
Returns a two-dimensional array of the range raw values. Empty cells return null.
Signature
getRawValues(): Array<Array<Nullable<CellValue>>>Returns
Nullable<CellValue>[][]— The raw value of the cell. Returnsnullif the cell is empty.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValues([
[
{
v: 0.2,
s: {
n: {
pattern: '0%',
},
},
},
{
v: 45658,
s: {
n: {
pattern: 'yyyy-mm-dd',
},
},
}
],
[
{
v: 1234.567,
s: {
n: {
pattern: '#,##0.00',
}
}
},
null,
],
]);
console.log(fRange.getRawValues()); // [[0.2, 45658], [1234.567, null]]@univerjs/sheets
getRectAreaData
Signature
getRectAreaData(options?: IRectAreaOptions): IRectAreaDataParameters
optionsIRectAreaOptions(optional) — No description
Returns
IRectAreaData— See signature above.
@univerjs-labs/sheets-mcp
getValue
Signature
getValue(includeRichText?: boolean): Nullable<CellValue | RichTextValue>Parameters
includeRichTextboolean(optional) — No description
Returns
Nullable<RichTextValue | CellValue>— See signature above.
@univerjs/sheets
getValueAndRichTextValues
Returns the value and rich text value for the cells in the range.
Signature
getValueAndRichTextValues(): Nullable<CellValue | RichTextValue>[][]Returns
Nullable<RichTextValue | CellValue>[][]— A two-dimensional array of value and rich text value
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getValueAndRichTextValues());@univerjs/sheets
getValues
Signature
getValues(includeRichText?: true): (Nullable<RichTextValue | CellValue>)[][]Parameters
includeRichTexttrue(optional) — No description
Returns
Nullable<RichTextValue | CellValue>[][]— See signature above.
@univerjs/sheets
setCustomMetaData
Set custom meta data for first cell in current range.
Signature
setCustomMetaData(data: CustomData): FRangeParameters
dataCustomData— No description
Returns
FRange— This range, for chaining
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setCustomMetaData({ key: 'value' });
console.log(fRange.getCustomMetaData());@univerjs/sheets
setCustomMetaDatas
Set custom meta data for current range.
Signature
setCustomMetaDatas(datas: CustomData[][]): FRangeParameters
datasCustomData[][]— No description
Returns
FRange— This range, for chaining
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setCustomMetaDatas([
[{ key: 'value' }, { key: 'value2' }],
[{ key: 'value3' }, { key: 'value4' }],
]);
console.log(fRange.getCustomMetaDatas());@univerjs/sheets
setDataValidation
Signature
setDataValidation(rule: Nullable<FDataValidation>): FRangeParameters
ruleNullable<FDataValidation>— No description
Returns
FRange— See signature above.
@univerjs/sheets-data-validation
setFormula
Updates the formula for this range. The given formula must be in A1 notation.
Signature
setFormula(formula: string): FRangeParameters
formulastring— No description
Returns
FRange— This range instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1');
fRange.setFormula('=SUM(A2:A5)');
console.log(fRange.getFormula()); // '=SUM(A2:A5)'@univerjs/sheets
setFormulas
Sets a rectangular grid of formulas (must match dimensions of this range). The given formulas must be in A1 notation.
Signature
setFormulas(formulas: string[][]): FRangeParameters
formulasstring[][]— No description
Returns
FRange— This range instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFormulas([
['=SUM(A2:A5)', '=SUM(B2:B5)'],
['=SUM(A6:A9)', '=SUM(B6:B9)'],
]);
console.log(fRange.getFormulas()); // [['=SUM(A2:A5)', '=SUM(B2:B5)'], ['=SUM(A6:A9)', '=SUM(B6:B9)']]@univerjs/sheets
setRichTextValueForCell
Set the rich text value for the cell at the start of this range.
Signature
setRichTextValueForCell(value: RichTextValue | IDocumentData): FRangeParameters
valueIDocumentData | RichTextValue— No description
Returns
FRange— The range
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getValue(true));
// Set A1 cell value to rich text
const richText = univerAPI.newRichText()
.insertText('Hello World')
.setStyle(0, 1, { bl: 1, cl: { rgb: '#c81e1e' } })
.setStyle(6, 7, { bl: 1, cl: { rgb: '#c81e1e' } });
fRange.setRichTextValueForCell(richText);
console.log(fRange.getValue(true).toPlainText()); // Hello World@univerjs/sheets
setRichTextValues
Set the rich text value for the cells in the range.
Signature
setRichTextValues(values: (RichTextValue | IDocumentData)[][]): FRangeParameters
values(IDocumentData | RichTextValue)[][]— No description
Returns
FRange— The range
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getValue(true));
// Set A1:B2 cell value to rich text
const richText = univerAPI.newRichText()
.insertText('Hello World')
.setStyle(0, 1, { bl: 1, cl: { rgb: '#c81e1e' } })
.setStyle(6, 7, { bl: 1, cl: { rgb: '#c81e1e' } });
fRange.setRichTextValues([
[richText, richText],
[null, null]
]);
console.log(fRange.getValue(true).toPlainText()); // Hello World@univerjs/sheets
setValue
Sets the value of the range.
Signature
setValue(value: CellValue | ICellData): FRangeParameters
valueCellValue | ICellData— No description
Returns
FRange— This range, for chaining
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('B2');
fRange.setValue(123);
// or
fRange.setValue({ v: 234, s: { bg: { rgb: '#ff0000' } } });@univerjs/sheets
setValueForCell
Set new value for current cell, first cell in this range.
Signature
setValueForCell(value: CellValue | ICellData): FRangeParameters
valueCellValue | ICellData— No description
Returns
FRange— This range, for chaining
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValueForCell(123);
// or
fRange.setValueForCell({ v: 234, s: { bg: { rgb: '#ff0000' } } });@univerjs/sheets
setValues
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.
Signature
setValues(value:
| CellValue[][]
| IObjectMatrixPrimitiveType<CellValue>
| ICellData[][]
| IObjectMatrixPrimitiveType<ICellData>): FRangeParameters
valueCellValue[][] | IObjectMatrixPrimitiveType<CellValue> | ICellData[][] | IObjectMatrixPrimitiveType<ICellData>— No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setValues([
[1, { v: 2, s: { bg: { rgb: '#ff0000' } } }],
[3, 4]
]);@univerjs/sheets
Style & Format
addConditionalFormattingRule
Signature
addConditionalFormattingRule(rule: IConditionFormattingRule): FRangeParameters
ruleIConditionFormattingRule— No description
Returns
FRange— See signature above.
@univerjs/sheets-conditional-formatting
clearConditionalFormatRules
Signature
clearConditionalFormatRules(): FRangeReturns
FRange— See signature above.
@univerjs/sheets-conditional-formatting
clearFormat
Clears formatting information of the range, while preserving contents.
Signature
clearFormat(): FRangeReturns
FRange— Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorkSheet = fWorkbook.getActiveSheet();
const fRange = fWorkSheet.getRange('A1:D10');
// clear the format only of the range A1:D10
fRange.clearFormat();@univerjs/sheets
createConditionalFormattingRule
Signature
createConditionalFormattingRule(): FConditionalFormattingBuilderReturns
FConditionalFormattingBuilder— See signature above.
@univerjs/sheets-conditional-formatting
deleteConditionalFormattingRule
Signature
deleteConditionalFormattingRule(cfId: string): FRangeParameters
cfIdstring— No description
Returns
FRange— See signature above.
@univerjs/sheets-conditional-formatting
getBackground
Returns the background color of the top-left cell in the range.
Signature
getBackground(): stringReturns
string— The color code of the background.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getBackground());@univerjs/sheets
getBackgrounds
Returns the background colors of the cells in the range.
Signature
getBackgrounds(): string[][]Returns
string[][]— A two-dimensional array of color codes of the backgrounds.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getBackgrounds());@univerjs/sheets
getCellStyle
Return first cell style in this range.
Signature
getCellStyle(type: GetStyleType = 'row'): TextStyleValue | nullParameters
typeGetStyleType(optional) — No description
Returns
TextStyleValue— The cell style
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellStyle());@univerjs/sheets
getCellStyles
Returns the cell styles for the cells in the range.
Signature
getCellStyles(type: GetStyleType = 'row'): Array<Array<TextStyleValue | null>>Parameters
typeGetStyleType(optional) — No description
Returns
TextStyleValue[][]— A two-dimensional array of cell styles.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getCellStyles());@univerjs/sheets
getConditionalFormattingRules
Signature
getConditionalFormattingRules(): IConditionFormattingRule[]Returns
IConditionFormattingRule[]— See signature above.
@univerjs/sheets-conditional-formatting
getFontFamily
Get the font family of the cell.
Signature
getFontFamily(type: GetStyleType = 'row'): string | nullParameters
typeGetStyleType(optional) — No description
Returns
string— The font family of the cell
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getFontFamily());@univerjs/sheets
getFontSize
Get the font size of the cell.
Signature
getFontSize(type: GetStyleType = 'row'): number | nullParameters
typeGetStyleType(optional) — No description
Returns
number— The font size of the cell
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getFontSize());@univerjs/sheets
getNumberFormat
Signature
getNumberFormat(): stringReturns
string— See signature above.
@univerjs/sheets-numfmt
getNumberFormats
Signature
getNumberFormats(): string[][]Returns
string[][]— See signature above.
@univerjs/sheets-numfmt
getStyleUsages
Signature
getStyleUsages(options?: IGetStyleUsagesOptions): IStyleUsage[]Parameters
optionsIGetStyleUsagesOptions(optional) — No description
Returns
IStyleUsage[]— See signature above.
@univerjs-labs/sheets-mcp
getStyleUsagesAsA1
Signature
getStyleUsagesAsA1(options?: IGetStyleUsagesOptions): IStyleUsageAsA1[]Parameters
optionsIGetStyleUsagesOptions(optional) — No description
Returns
IStyleUsageAsA1[]— See signature above.
@univerjs-labs/sheets-mcp
getUsedThemeStyle
Gets the theme style applied to the range.
Signature
getUsedThemeStyle(): string | undefinedReturns
string— The name of the theme style applied to the range or not exist.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:E20');
console.log(fRange.getUsedThemeStyle()); // undefined
fRange.useThemeStyle('default');
console.log(fRange.getUsedThemeStyle()); // 'default'@univerjs/sheets
moveConditionalFormattingRule
Signature
moveConditionalFormattingRule(cfId: string, toCfId: string, type: IAnchor['type'] = 'after'): FRangeParameters
cfIdstring— No descriptiontoCfIdstring— No descriptiontypeIAnchor(optional) — No description
Returns
FRange— See signature above.
@univerjs/sheets-conditional-formatting
removeThemeStyle
Remove the theme style for the range.
Signature
removeThemeStyle(themeName: string): voidParameters
themeNamestring— No description
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:E20');
fRange.removeThemeStyle('default');@univerjs/sheets
setBackground
Set background color for current range.
Signature
setBackground(color: string): FRangeParameters
colorstring— No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setBackground('red');@univerjs/sheets
setBackgroundColor
Set background color for current range.
Signature
setBackgroundColor(color: string): FRangeParameters
colorstring— No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setBackgroundColor('red');@univerjs/sheets
setBorder
Sets basic border properties for the current range.
Signature
setBorder(type: BorderType, style: BorderStyleTypes, color?: string): FRangeParameters
typeBorderType— No descriptionstyleBorderStyleTypes— No descriptioncolorstring(optional) — No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setBorder(univerAPI.Enum.BorderType.ALL, univerAPI.Enum.BorderStyleTypes.THIN, '#ff0000');@univerjs/sheets
setConditionalFormattingRule
Signature
setConditionalFormattingRule(cfId: string, rule: IConditionFormattingRule): FRangeParameters
cfIdstring— No descriptionruleIConditionFormattingRule— No description
Returns
FRange— See signature above.
@univerjs/sheets-conditional-formatting
setFontColor
Sets the font color in CSS notation (such as '#ffffff' or 'white').
Signature
setFontColor(color: string | null): thisParameters
colorstring— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontColor('#ff0000');@univerjs/sheets
setFontFamily
Sets the font family, such as "Arial" or "Helvetica".
Signature
setFontFamily(fontFamily: string | null): thisParameters
fontFamilystring— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontFamily('Arial');@univerjs/sheets
setFontLine
Sets the font line style of the given range ('underline', 'line-through', or 'none').
Signature
setFontLine(fontLine: FontLine | null): thisParameters
fontLineFontLine— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontLine('underline');@univerjs/sheets
setFontSize
Sets the font size, with the size being the point size to use.
Signature
setFontSize(size: number | null): thisParameters
sizenumber— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontSize(24);@univerjs/sheets
setFontStyle
Sets the font style for the given range ('italic' or 'normal').
Signature
setFontStyle(fontStyle: FontStyle | null): thisParameters
fontStyleFontStyle— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontStyle('italic');@univerjs/sheets
setFontWeight
Sets the font weight for the given range (normal/bold),
Signature
setFontWeight(fontWeight: FontWeight | null): thisParameters
fontWeightFontWeight— No description
Returns
this— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setFontWeight('bold');@univerjs/sheets
setNumberFormat
Signature
setNumberFormat(pattern: string): FRangeParameters
patternstring— No description
Returns
FRange— See signature above.
@univerjs/sheets-numfmt
setNumberFormats
Signature
setNumberFormats(patterns: string[][]): FRangeParameters
patternsstring[][]— No description
Returns
FRange— See signature above.
@univerjs/sheets-numfmt
useThemeStyle
Set the theme style for the range.
Signature
useThemeStyle(themeName: string | undefined): voidParameters
themeNamestring— No description
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:E20');
fRange.useThemeStyle('default');@univerjs/sheets
Geometry & Size
getCellRect
Signature
getCellRect(): DOMRectReturns
DOMRect— See signature above.
@univerjs/sheets-ui
getColumn
Gets the starting column index of the range. index starts at 0.
Signature
getColumn(): numberReturns
number— The starting column index of the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getColumn()); // 0@univerjs/sheets
getHeight
Gets the height of the applied area
Signature
getHeight(): numberReturns
number— The height of the area
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getHeight());@univerjs/sheets
getLastColumn
Gets the ending column index of the range. index starts at 0.
Signature
getLastColumn(): numberReturns
number— The ending column index of the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getLastColumn()); // 1@univerjs/sheets
getLastRow
Gets the ending row index of the range. index starts at 0.
Signature
getLastRow(): numberReturns
number— The ending row index of the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getLastRow()); // 1@univerjs/sheets
getRectArea
Signature
getRectArea(options?: IRectAreaOptions): IRectAreaParameters
optionsIRectAreaOptions(optional) — No description
Returns
IRectArea— See signature above.
@univerjs-labs/sheets-mcp
getRow
Gets the starting row index of the range. index starts at 0.
Signature
getRow(): numberReturns
number— The starting row index of the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getRow()); // 0@univerjs/sheets
getWidth
Gets the width of the applied area
Signature
getWidth(): numberReturns
number— The width of the area
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getWidth());@univerjs/sheets
splitTextToColumns
Splits a column of text into multiple columns based on a custom specified delimiter.
Signature
splitTextToColumns(treatMultipleDelimitersAsOne?: boolean, delimiter?: SplitDelimiterEnum, customDelimiter?: string): voidParameters
treatMultipleDelimitersAsOneboolean(optional) — No descriptiondelimiterSplitDelimiterEnum(optional) — No descriptioncustomDelimiterstring(optional) — No description
Examples
Show how to split text to columns with custom delimiter
```ts
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// A1:A3 has following values:
// A |
// 1#2#3 |
// 4##5#6 |
const fRange = fWorksheet.getRange('A1:A3');
fRange.setValues([
['A'],
['1#2#3'],
['4##5#6']
]);
// After calling splitTextToColumns(false, univerAPI.Enum.SplitDelimiterType.Custom, '#'), the range will be:
// A | | |
// 1 | 2 | 3 |
// 4 | | 5 | 6
fRange.splitTextToColumns(false, univerAPI.Enum.SplitDelimiterType.Custom, '#');
// After calling splitTextToColumns(true, univerAPI.Enum.SplitDelimiterType.Custom, '#'), the range will be:
// A | |
// 1 | 2 | 3
// 4 | 5 | 6
fRange.splitTextToColumns(true, univerAPI.Enum.SplitDelimiterType.Custom, '#');@univerjs/sheets
Merge & Clear
breakApart
Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
Signature
breakApart(): FRangeReturns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.merge();
const anchor = fWorksheet.getRange('A1');
console.log(anchor.isPartOfMerge()); // true
fRange.breakApart();
console.log(anchor.isPartOfMerge()); // false@univerjs/sheets
clear
Clears content and formatting information of the range. Or Optionally clears only the contents or only the formatting.
Signature
clear(options?: IFacadeClearOptions): FRangeParameters
optionsIFacadeClearOptions(optional) — No description
Returns
FRange— Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorkSheet = fWorkbook.getActiveSheet();
const fRange = fWorkSheet.getRange('A1:D10');
// clear the content and format of the range A1:D10
fRange.clear();
// clear the content only of the range A1:D10
fRange.clear({ contentsOnly: true });@univerjs/sheets
clearComment
Signature
clearComment(): Promise<boolean>Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
clearCommentAsync
Signature
clearCommentAsync(): Promise<boolean>Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
clearComments
Signature
clearComments(): Promise<boolean>Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
clearCommentsAsync
Signature
clearCommentsAsync(): Promise<boolean>Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
clearContent
Clears content of the range, while preserving formatting information.
Signature
clearContent(): FRangeReturns
FRange— Returns the current worksheet instance for method chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorkSheet = fWorkbook.getActiveSheet();
const fRange = fWorkSheet.getRange('A1:D10');
// clear the content only of the range A1:D10
fRange.clearContent();@univerjs/sheets
deleteCells
Deletes this range of cells. Existing data in the sheet along the provided dimension is shifted towards the deleted range.
Signature
deleteCells(shiftDimension: Dimension): voidParameters
shiftDimensionDimension— No description
Examples
// Assume the active sheet empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const values = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7],
[5, 6, 7, 8],
];
// Set the range A1:D5 with some values, the range A1:D5 will be:
// 1 | 2 | 3 | 4
// 2 | 3 | 4 | 5
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
const fRange = fWorksheet.getRange('A1:D5');
fRange.setValues(values);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]
// Delete the range A1:B2 along the columns dimension, the range A1:D5 will be:
// 3 | 4 | |
// 4 | 5 | |
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
const fRange2 = fWorksheet.getRange('A1:B2');
fRange2.deleteCells(univerAPI.Enum.Dimension.COLUMNS);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[3, 4, null, null], [4, 5, null, null], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]
// Set the range A1:D5 values again, the range A1:D5 will be:
// 1 | 2 | 3 | 4
// 2 | 3 | 4 | 5
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
fRange.setValues(values);
// Delete the range A1:B2 along the rows dimension, the range A1:D5 will be:
// 3 | 4 | 3 | 4
// 4 | 5 | 4 | 5
// 5 | 6 | 5 | 6
// | | 6 | 7
// | | 7 | 8
const fRange3 = fWorksheet.getRange('A1:B2');
fRange3.deleteCells(univerAPI.Enum.Dimension.ROWS);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[3, 4, 3, 4], [4, 5, 4, 5], [5, 6, 5, 6], [null, null, 6, 7], [null, null, 7, 8]]@univerjs/sheets
deleteNote
Signature
deleteNote(): FRangeReturns
FRange— See signature above.
@univerjs/sheets-note
isMerged
Return range whether this range is merged
Signature
isMerged(): booleanReturns
boolean— if true is merged
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.isMerged());
// merge cells A1:B2
fRange.merge();
console.log(fRange.isMerged());@univerjs/sheets
isPartOfMerge
Returns true if cells in the current range overlap a merged cell.
Signature
isPartOfMerge(): booleanReturns
boolean— is overlap with a merged cell
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.merge();
const anchor = fWorksheet.getRange('A1');
console.log(anchor.isPartOfMerge()); // true@univerjs/sheets
merge
Merge cells in a range into one merged cell
Signature
merge(options?: IMergeCellsUtilOptions): FRangeParameters
optionsIMergeCellsUtilOptions(optional) — No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.merge();
console.log(fRange.isMerged());const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('B1:C2');
// Assume A1:B2 is already merged.
fRange.merge({ isForceMerge: true });@univerjs/sheets
mergeAcross
Merges cells in a range horizontally.
Signature
mergeAcross(options?: IMergeCellsUtilOptions): FRangeParameters
optionsIMergeCellsUtilOptions(optional) — No description
Returns
FRange— This range, for chaining
Examples
// Assume the active sheet is a new sheet with no merged cells.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.mergeAcross();
// There will be two merged cells. A1:B1 and A2:B2.
const mergeData = fWorksheet.getMergeData();
mergeData.forEach((item) => {
console.log(item.getA1Notation());
});const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('B1:C2');
// Assume A1:B2 is already merged.
fRange.mergeAcross({ isForceMerge: true });@univerjs/sheets
mergeVertically
Merges cells in a range vertically.
Signature
mergeVertically(options?: IMergeCellsUtilOptions): FRangeParameters
optionsIMergeCellsUtilOptions(optional) — No description
Returns
FRange— This range, for chaining
Examples
// Assume the active sheet is a new sheet with no merged cells.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.mergeVertically();
// There will be two merged cells. A1:A2 and B1:B2.
const mergeData = fWorksheet.getMergeData();
mergeData.forEach((item) => {
console.log(item.getA1Notation());
});const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('B1:C2');
// Assume A1:B2 is already merged.
fRange.mergeVertically({ isForceMerge: true });@univerjs/sheets
Analysis
getSizeUsages
Signature
getSizeUsages(options?: IGetSizeUsagesOptions): ISizeUsageGroupedParameters
optionsIGetSizeUsagesOptions(optional) — No description
Returns
ISizeUsageGrouped— See signature above.
@univerjs-labs/sheets-mcp
getSizeUsagesAsA1
Signature
getSizeUsagesAsA1(options?: IGetSizeUsagesOptions): ISizeUsageGroupedAsA1Parameters
optionsIGetSizeUsagesOptions(optional) — No description
Returns
ISizeUsageGroupedAsA1— See signature above.
@univerjs-labs/sheets-mcp
Miscellaneous
activate
Sets the specified range as the active range, with the top left cell in the range as the current cell.
Signature
activate(): FRangeReturns
FRange— This range, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.activate(); // the active cell will be A1@univerjs/sheets
activateAsCurrentCell
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.
Signature
activateAsCurrentCell(): FRangeReturns
FRange— This range, for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// Set the range A1:B2 as the active range, default active cell is A1
const fRange = fWorksheet.getRange('A1:B2');
fRange.activate();
console.log(fWorksheet.getActiveRange().getA1Notation()); // A1:B2
console.log(fWorksheet.getActiveCell().getA1Notation()); // A1
// Set the cell B2 as the active cell
// Because B2 is in the active range A1:B2, the active range will not change, and the active cell will be changed to B2
const cell = fWorksheet.getRange('B2');
cell.activateAsCurrentCell();
console.log(fWorksheet.getActiveRange().getA1Notation()); // A1:B2
console.log(fWorksheet.getActiveCell().getA1Notation()); // B2
// Set the cell C3 as the active cell
// Because C3 is not in the active range A1:B2, a new active range C3:C3 will be created, and the active cell will be changed to C3
const cell2 = fWorksheet.getRange('C3');
cell2.activateAsCurrentCell();
console.log(fWorksheet.getActiveRange().getA1Notation()); // C3:C3
console.log(fWorksheet.getActiveCell().getA1Notation()); // C3@univerjs/sheets
addComment
Signature
addComment(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>Parameters
contentIDocumentBody | FTheadCommentBuilder— No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
addCommentAsync
Signature
addCommentAsync(content: IDocumentBody | FTheadCommentBuilder): Promise<boolean>Parameters
contentIDocumentBody | FTheadCommentBuilder— No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-thread-comment
attachAlertPopup
Signature
attachAlertPopup(alert: Omit<ICellAlert, 'location'>): IDisposableParameters
alertOmit<ICellAlert, "location">— No description
Returns
IDisposable— See signature above.
@univerjs/sheets-ui
attachPopup
Signature
attachPopup(popup: IFCanvasPopup): Nullable<IDisposable>Parameters
popupIFCanvasPopup— No description
Returns
any— See signature above.
@univerjs/sheets-ui
attachRangePopup
attachDOMPopup
Signature
attachRangePopup(popup: IFCanvasPopup): Nullable<IDisposable>Parameters
popupIFCanvasPopup— No description
Returns
any— disposable let sheet = univerAPI.getActiveWorkbook().getActiveSheet(); let range = sheet.getRange(2, 2, 3, 3); univerAPI.getActiveWorkbook().setActiveRange(range); let disposable = range.attachDOMPopup({ componentKey: 'univer.sheet.single-dom-popup', extraProps: { alert: { type: 0, title: 'This is an Info', message: 'This is an info message' } }, });
@univerjs/sheets-ui
autoFill
Fills the target range with data based on the data in the current range.
Signature
autoFill(targetRange: FRange, applyType?: AUTO_FILL_APPLY_TYPE): Promise<boolean>Parameters
targetRangeFRange— No descriptionapplyTypeAUTO_FILL_APPLY_TYPE(optional) — No description
Returns
Promise<boolean>— A promise that resolves to true if the fill operation was successful, false otherwise.
Examples
// Auto-fill the range D1:D10 based on the data in the range C1:C2
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:A4');
// Auto-fill without specifying applyType (default behavior)
await fRange.autoFill(fWorksheet.getRange('A1:A20'))
// Auto-fill with 'COPY' type
await fRange.autoFill(fWorksheet.getRange('A1:A20'), 'COPY')
// Auto-fill with 'SERIES' type
await fRange.autoFill(fWorksheet.getRange('A1:A20'), 'SERIES')// Operate on a specific worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getSheetBySheetId('sheetId');
const fRange = fWorksheet.getRange('A1:A4');
// Auto-fill without specifying applyType (default behavior)
await fRange.autoFill(fWorksheet.getRange('A1:A20'))
// Auto-fill with 'COPY' type
await fRange.autoFill(fWorksheet.getRange('A1:A20'), 'COPY')
// Auto-fill with 'SERIES' type
await fRange.autoFill(fWorksheet.getRange('A1:A20'), 'SERIES')@univerjs/sheets
cancelHyperLink
Signature
cancelHyperLink(id: string): booleanParameters
idstring— No description
Returns
boolean— See signature above.
@univerjs/sheets-hyper-link
createFilter
Signature
createFilter(): FFilter | nullReturns
FFilter— See signature above.
@univerjs/sheets-filter
createOrUpdateNote
Signature
createOrUpdateNote(note: ISheetNote): FRangeParameters
noteISheetNote— No description
Returns
FRange— See signature above.
@univerjs/sheets-note
forEach
Iterate cells in this range. Merged cells will be respected.
Signature
forEach(callback: (row: number, col: number, cell: ICellData) => void): voidParameters
callback(row: number, col: number, cell: ICellData) => void— No description
@univerjs/sheets
generateHTML
Signature
generateHTML(): stringReturns
string— See signature above.
@univerjs/sheets-ui
getA1Notation
Returns a string description of the range, in A1 notation.
Signature
getA1Notation(withSheet?: boolean, startAbsoluteRefType?: AbsoluteRefType, endAbsoluteRefType?: AbsoluteRefType): stringParameters
withSheetboolean(optional) — No descriptionstartAbsoluteRefTypeAbsoluteRefType(optional) — No descriptionendAbsoluteRefTypeAbsoluteRefType(optional) — No description
Returns
string— The A1 notation of the range.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// By default, the A1 notation is returned without the sheet name and without absolute reference types.
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getA1Notation()); // A1:B2
// By setting withSheet to true, the sheet name is included in the A1 notation.
fWorksheet.setName('Sheet1');
console.log(fRange.getA1Notation(true)); // Sheet1!A1:B2
// By setting startAbsoluteRefType, the absolute reference type for the start cell is included in the A1 notation.
console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.ROW)); // A$1:B2
console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.COLUMN)); // $A1:B2
console.log(fRange.getA1Notation(false, univerAPI.Enum.AbsoluteRefType.ALL)); // $A$1:B2
// By setting endAbsoluteRefType, the absolute reference type for the end cell is included in the A1 notation.
console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.ROW)); // A1:B$2
console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.COLUMN)); // A1:$B2
console.log(fRange.getA1Notation(false, null, univerAPI.Enum.AbsoluteRefType.ALL)); // A1:$B$2
// By setting all parameters example
console.log(fRange.getA1Notation(true, univerAPI.Enum.AbsoluteRefType.ALL, univerAPI.Enum.AbsoluteRefType.ALL)); // Sheet1!$A$1:$B$2@univerjs/sheets
getCell
Signature
getCell(): ICellWithCoordReturns
ICellWithCoord— See signature above.
@univerjs/sheets-ui
getComment
Signature
getComment(): Nullable<FThreadComment>Returns
Nullable<FThreadComment>— See signature above.
@univerjs/sheets-thread-comment
getComments
Signature
getComments(): FThreadComment[]Returns
FThreadComment[]— See signature above.
@univerjs/sheets-thread-comment
getFilter
Get the filter for the current range's worksheet.
Signature
getFilter(): FFilter | nullReturns
FFilter— The interface class to handle the filter. If the worksheet does not have a filter, this method would returnnull.
@univerjs/sheets-filter
getHorizontalAlignment
Returns the horizontal alignment of the text (left/center/right) of the top-left cell in the range.
Signature
getHorizontalAlignment(): stringReturns
string— The horizontal alignment of the text in the cell.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getHorizontalAlignment());@univerjs/sheets
getHorizontalAlignments
Returns the horizontal alignments of the cells in the range.
Signature
getHorizontalAlignments(): string[][]Returns
string[][]— A two-dimensional array of horizontal alignments of text associated with cells in the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getHorizontalAlignments());@univerjs/sheets
getHyperLinks
Signature
getHyperLinks(): ICellHyperLink[]Returns
ICellHyperLink[]— See signature above.
@univerjs/sheets-hyper-link
getNote
Signature
getNote(): Nullable<ISheetNote>Returns
any— See signature above.
@univerjs/sheets-note
getRange
Gets the area where the statement is applied
Signature
getRange(): IRangeReturns
IRange— The area where the statement is applied
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const range = fRange.getRange();
const { startRow, startColumn, endRow, endColumn } = range;
console.log(range);@univerjs/sheets
getRangePermission
Get the RangePermission instance for managing range-level permissions. This is the new permission API that provides range-specific permission control.
Signature
getRangePermission(): FRangePermissionReturns
FRangePermission— - The RangePermission instance.
Examples
const fWorksheet = univerAPI.getActiveWorkbook().getActiveSheet();
const fRange = fWorksheet.getRange('A1:B10');
const permission = fRange.getRangePermission();
// Protect the range
await permission.protect({ name: 'Protected Area', allowEdit: false });
// Check if range is protected
const isProtected = permission.isProtected();
// Check if current user can edit
const canEdit = permission.canEdit();
// Unprotect the range
await permission.unprotect();
// Subscribe to protection changes
permission.protectionChange$.subscribe(change => {
console.log('Protection changed:', change);
});@univerjs/sheets
getScreenshot
Signature
getScreenshot(options?: IRangeScreenshotOptions): string | falseParameters
optionsIRangeScreenshotOptions(optional) — No description
Returns
string | false— See signature above.
@univerjs-pro/sheets-print
getScreenshotOnNode
Signature
async getScreenshotOnNode(options?: INodeRangeScreenshotOptions): Promise<string | false>Parameters
optionsINodeRangeScreenshotOptions(optional) — No description
Returns
Promise<string | false>— See signature above.
@univerjs-labs/sheets-node-screenshot
getSheetId
Gets the ID of the worksheet
Signature
getSheetId(): stringReturns
string— The ID of the worksheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getSheetId());@univerjs/sheets
getSheetName
Gets the name of the worksheet
Signature
getSheetName(): stringReturns
string— The name of the worksheet
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getSheetName());@univerjs/sheets
getUnitId
Get the unit ID of the current workbook
Signature
getUnitId(): stringReturns
string— The unit ID of the workbook
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getUnitId());@univerjs/sheets
getUrl
Signature
getUrl(): stringReturns
string— See signature above.
@univerjs/sheets-hyper-link
getValidatorStatus
Signature
async getValidatorStatus(): Promise<DataValidationStatus[][]>Returns
Promise<DataValidationStatus[][]>— See signature above.
@univerjs/sheets-data-validation
getVerticalAlignment
Returns the vertical alignment (top/middle/bottom) of the top-left cell in the range.
Signature
getVerticalAlignment(): stringReturns
string— The vertical alignment of the text in the cell.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getVerticalAlignment());@univerjs/sheets
getVerticalAlignments
Returns the vertical alignments of the cells in the range.
Signature
getVerticalAlignments(): string[][]Returns
string[][]— A two-dimensional array of vertical alignments of text associated with cells in the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getVerticalAlignments());@univerjs/sheets
getWrap
Gets whether text wrapping is enabled for top-left cell in the range.
Signature
getWrap(): booleanReturns
boolean— whether text wrapping is enabled for the cell.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getWrap());@univerjs/sheets
getWraps
Gets whether text wrapping is enabled for cells in the range.
Signature
getWraps(): boolean[][]Returns
boolean[][]— A two-dimensional array of whether text wrapping is enabled for each cell in the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getWraps());@univerjs/sheets
getWrapStrategy
Returns the text wrapping strategy for the top left cell of the range.
Signature
getWrapStrategy(): WrapStrategyReturns
WrapStrategy— The text wrapping strategy
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getWrapStrategy());@univerjs/sheets
highlight
Signature
highlight(style?: Nullable<Partial<ISelectionStyle>>, primary?: Nullable<ISelectionCell>): IDisposableParameters
styleNullable<Partial<ISelectionStyle>>(optional) — No descriptionprimaryNullable<ISelectionCell>(optional) — No description
Returns
IDisposable— See signature above.
@univerjs/sheets-ui
insertCellImageAsync
Signature
async insertCellImageAsync(file: File | string): Promise<boolean>Parameters
filestring | File— No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-drawing-ui
insertCells
Inserts empty cells into this range. Existing data in the sheet along the provided dimension is shifted away from the inserted range.
Signature
insertCells(shiftDimension: Dimension): voidParameters
shiftDimensionDimension— No description
Examples
// Assume the active sheet empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const values = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7],
[5, 6, 7, 8],
];
// Set the range A1:D5 with some values, the range A1:D5 will be:
// 1 | 2 | 3 | 4
// 2 | 3 | 4 | 5
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
const fRange = fWorksheet.getRange('A1:D5');
fRange.setValues(values);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]
// Insert the empty cells into the range A1:B2 along the columns dimension, the range A1:D5 will be:
// | | 1 | 2
// | | 2 | 3
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
const fRange2 = fWorksheet.getRange('A1:B2');
fRange2.insertCells(univerAPI.Enum.Dimension.COLUMNS);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[null, null, 1, 2], [null, null, 2, 3], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]]
// Set the range A1:D5 values again, the range A1:D5 will be:
// 1 | 2 | 3 | 4
// 2 | 3 | 4 | 5
// 3 | 4 | 5 | 6
// 4 | 5 | 6 | 7
// 5 | 6 | 7 | 8
fRange.setValues(values);
// Insert the empty cells into the range A1:B2 along the rows dimension, the range A1:D5 will be:
// | | 3 | 4
// | | 4 | 5
// 1 | 2 | 5 | 6
// 2 | 3 | 6 | 7
// 3 | 4 | 7 | 8
const fRange3 = fWorksheet.getRange('A1:B2');
fRange3.insertCells(univerAPI.Enum.Dimension.ROWS);
console.log(fWorksheet.getRange('A1:D5').getValues()); // [[null, null, 3, 4], [null, null, 4, 5], [1, 2, 5, 6], [2, 3, 6, 7], [3, 4, 7, 8]]@univerjs/sheets
isBlank
Returns true if the range is totally blank.
Signature
isBlank(): booleanReturns
boolean— true if the range is blank; false otherwise.
Examples
// Assume the active sheet is a new sheet with no data.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.isBlank()); // true
// Set the range A1:B2 with some values
fRange.setValueForCell(123);
console.log(fRange.isBlank()); // false@univerjs/sheets
offset
Returns a new range that is relative to the current range, whose upper left point is offset from the current range by the given rows and columns, and with the given height and width in cells.
Signature
offset(rowOffset: number, columnOffset: number, numRows?: number, numColumns?: number): FRangeParameters
rowOffsetnumber— No descriptioncolumnOffsetnumber— No descriptionnumRowsnumber(optional) — No descriptionnumColumnsnumber(optional) — No description
Returns
FRange— The new range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
console.log(fRange.getA1Notation()); // A1:B2
// Offset the range by 1 row and 1 column, and set the height of the new range to 3 and the width to 3
const newRange = fRange.offset(1, 1, 3, 3);
console.log(newRange.getA1Notation()); // B2:D4@univerjs/sheets
saveCellImagesAsync
Signature
async saveCellImagesAsync(options?: ISaveCellImagesOptions): Promise<boolean>Parameters
optionsISaveCellImagesOptions(optional) — No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-drawing-ui
setHorizontalAlignment
Set the horizontal (left to right) alignment for the given range (left/center/right).
Signature
setHorizontalAlignment(alignment: FHorizontalAlignment): FRangeParameters
alignmentFHorizontalAlignment— No description
Returns
FRange— this range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setHorizontalAlignment('left');@univerjs/sheets
setHyperLink
Signature
setHyperLink(url: string, label?: string): Promise<boolean>Parameters
urlstring— No descriptionlabelstring(optional) — No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-hyper-link
setTextRotation
Set rotation for text in current range.
Signature
setTextRotation(rotation: number): FRangeParameters
rotationnumber— No description
Returns
FRange— This range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setTextRotation(45);@univerjs/sheets
setVerticalAlignment
Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
Signature
setVerticalAlignment(alignment: FVerticalAlignment): FRangeParameters
alignmentFVerticalAlignment— No description
Returns
FRange— this range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setVerticalAlignment('top');@univerjs/sheets
setWrap
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.
Signature
setWrap(isWrapEnabled: boolean): FRangeParameters
isWrapEnabledboolean— No description
Returns
FRange— this range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setWrap(true);
console.log(fRange.getWrap());@univerjs/sheets
setWrapStrategy
Sets the text wrapping strategy for the cells in the range.
Signature
setWrapStrategy(strategy: WrapStrategy): FRangeParameters
strategyWrapStrategy— No description
Returns
FRange— this range, for chaining
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
fRange.setWrapStrategy(univerAPI.Enum.WrapStrategy.WRAP);
console.log(fRange.getWrapStrategy());@univerjs/sheets
showDropdown
Signature
showDropdown(param: IDropdownParam): IDisposableParameters
paramIDropdownParam— No description
Returns
IDisposable— See signature above.
@univerjs/sheets-ui
sort
Signature
sort(column: SortColumnSpec | SortColumnSpec[]): FRangeParameters
columnSortColumnSpec | SortColumnSpec[]— No description
Returns
FRange— See signature above.
@univerjs/sheets-sort
updateHyperLink
Signature
updateHyperLink(id: string, url: string, label?: string): Promise<boolean>Parameters
idstring— No descriptionurlstring— No descriptionlabelstring(optional) — No description
Returns
Promise<boolean>— See signature above.
@univerjs/sheets-hyper-link