Class: FWorkbook
Facade API object bounded to a workbook. It provides a set of methods to interact with the workbook.
Extends
FBaseInitialable
.IFWorkbookThreadCommentMixin
.IFWorkbookNumfmtMixin
.IFWorkbookDataValidationMixin
.IFWorkbookHyperlinkMixin
.IFWorkbookConditionalFormattingMixin
.IFWorkbookSheetsPivotMixin
.IFWorkbookSheetsUIMixin
.IFWorkbookSheetsZenEditorMixin
.IFWorkbookSheetsPrintMixin
Properties
Property | Modifier | Type |
---|---|---|
|
|
Methods
addPivotTable()
addPivotTable(
sourceInfo,
positionType,
anchorCellInfo): Promise<FPivotTable>
Parameters
Parameter | Type | Description |
---|---|---|
sourceInfo | any | The source data range info of the pivot table. |
positionType | PositionType | whether new a sheet or insert a pivot table to the existing sheet. |
anchorCellInfo | IPivotCellPositionInfo | The target cell info of the pivot table. |
Returns
Promise
<FPivotTable
>
The added pivot table id.
Description
Add a pivot table to the Workbook.
Example
// should ensure the sheet range {0,0,8,6} is not empty
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook.getId();
const fSheet = fWorkbook.getActiveSheet();
const subUnitId = fSheet.getSheetId();
const sheetName = fSheet.getSheetName();
const sourceInfo = {
unitId,
subUnitId,
sheetName,
range: {
startRow: 0,
endRow: 8,
startColumn: 0,
endColumn: 6
}
};
const anchorCellInfo = {
unitId,
subUnitId,
row: 20,
col: 8
};
const fPivotTable = await fWorkbook.addPivotTable(sourceInfo, 'existing', anchorCellInfo);
const pivotTableId = fPivotTable.getPivotTableId();
let hasAdded = false;
// the addPivotTable is async, you can add pivot fields after the pivot table is added
univerAPI.addEvent(univerAPI.Event.PivotTableRendered, (params) => {
if (!hasAdded && params.pivotTableId === pivotTableId) {
fPivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0);
fPivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Value, 0);
hasAdded = true;
}
});
clearComments()
clearComments(): Promise<boolean>
Clear all comments in the current sheet
Returns
Promise
<boolean
>
Whether the comments are cleared successfully.
Example
const workbook = univerAPI.getActiveWorkbook();
const success = await workbook.clearComments();
closePrintDialog()
closePrintDialog(): void
close print dialog
Returns
void
Example
univerAPI.getActiveWorkbook().closePrintDialog();
create()
create(
name,
rows,
column): FWorksheet
Create a new worksheet and returns a handle to it.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | Name of the new sheet |
rows | number | How many rows would the new sheet have |
column | number | How many columns would the new sheet have |
Returns
The new created sheet
Example
// The code below creates a new sheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const newSheet = activeSpreadsheet.create('MyNewSheet', 10, 10);
createRangeThemeStyle()
createRangeThemeStyle(themeName, themeStyleJson?): RangeThemeStyle
Parameters
Parameter | Type |
---|---|
themeName | string |
themeStyleJson ? | Omit <IRangeThemeStyleJSON , "name" > |
Returns
RangeThemeStyle
createSheetHyperlink()
createSheetHyperlink(
this,
sheetId,
range?): string
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
sheetId | string |
range ? | string | IRange |
Returns
string
Deprecated
use getUrl
method in FRange
or FWorksheet
instead.
deleteActiveSheet()
deleteActiveSheet(): boolean
Deletes the currently active sheet.
Returns
boolean
true if the sheet was deleted, false otherwise
Example
// The code below deletes the currently active sheet and stores the new active
// sheet in a variable
const sheet = univerAPI.getActiveWorkbook().deleteActiveSheet();
deleteDefinedName()
deleteDefinedName(name): boolean
Delete the defined name with the given name.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | The name of the defined name to delete |
Returns
boolean
true if the defined name was deleted, false otherwise
Example
// The code below deletes the defined name with the given name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const deleted = activeSpreadsheet.deleteDefinedName('MyDefinedName');
deleteSheet()
deleteSheet(sheet): boolean
Deletes the specified worksheet.
Parameters
Parameter | Type | Description |
---|---|---|
sheet | string | FWorksheet | The worksheet to delete. |
Returns
boolean
True if the worksheet was deleted, false otherwise.
Example
// The code below deletes the specified worksheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheet = activeSpreadsheet.getSheetByName('Sheet1');
activeSpreadsheet.deleteSheet(sheet);
disableSelection()
disableSelection(): FWorkbook
Disable selection. After disabled, there would be no response for selection.
Returns
FWorkbook instance
Example
univerAPI.getActiveWorkbook().disableSelection();
duplicateActiveSheet()
duplicateActiveSheet(): FWorksheet
Duplicates the active sheet.
Returns
The duplicated worksheet
Example
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.duplicateActiveSheet();
duplicateSheet()
duplicateSheet(sheet): FWorksheet
Duplicates the given worksheet.
Parameters
Parameter | Type | Description |
---|---|---|
sheet | FWorksheet | The worksheet to duplicate. |
Returns
The duplicated worksheet
Example
// The code below duplicates the given worksheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const activeSheet = activeSpreadsheet.getActiveSheet();
activeSpreadsheet.duplicateSheet(activeSheet);
enableSelection()
enableSelection(): FWorkbook
Enable selection. After this you can select range.
Returns
Example
univerAPI.getActiveWorkbook().enableSelection();
endEditing()
endEditing(save?): Promise<boolean>
Parameters
Parameter | Type |
---|---|
save ? | boolean |
Returns
Promise
<boolean
>
Deprecated
Use endEditingAsync
as instead
endEditingAsync()
endEditingAsync(save?): Promise<boolean>
Parameters
Parameter | Type | Description |
---|---|---|
save ? | boolean | Whether to save the changes, default is true |
Returns
Promise
<boolean
>
A promise that resolves to a boolean value
Async
End the editing process
Example
await univerAPI.getActiveWorkbook().endEditingAsync(false);
endZenEditingAsync()
endZenEditingAsync(save?): Promise<boolean>
End the zen editing process
Parameters
Parameter | Type | Description |
---|---|---|
save ? | boolean | Whether to save the changes, default is true |
Returns
Promise
<boolean
>
A promise that resolves to a boolean indicating whether the zen editing process was ended successfully.
Async
Example
univerAPI.getActiveWorkbook().endZenEditingAsync(false);
getActiveRange()
getActiveRange(): FRange
Returns the selected range in the active sheet, or null if there is no active range.
Returns
The active range
getActiveSheet()
getActiveSheet(): FWorksheet
Get the active sheet of the workbook.
Returns
The active sheet of the workbook
Example
// The code below gets the active sheet of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const activeSheet = activeSpreadsheet.getActiveSheet();
getComments()
getComments(): FThreadComment[]
Get all comments in the current sheet
Returns
all comments in the current sheet
Example
const workbook = univerAPI.getActiveWorkbook();
const comments = workbook.getComments();
getCustomMetadata()
getCustomMetadata(): CustomData
Get custom metadata of workbook
Returns
custom metadata
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const custom = fWorkbook.getCustomMetadata();
getDefinedName()
getDefinedName(name): FDefinedName
Get the defined name by name.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | The name of the defined name to get |
Returns
The defined name with the given name
Example
// The code below gets the defined name by name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const definedName = activeSpreadsheet.getDefinedName('MyDefinedName');
getDefinedNames()
getDefinedNames(): FDefinedName[]
Get all the defined names in the workbook.
Returns
All the defined names in the workbook
Example
// The code below gets all the defined names in the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const definedNames = activeSpreadsheet.getDefinedNames();
getId()
getId(): string
Get the id of the workbook.
Returns
string
The id of the workbook.
Example
// The code below gets the id of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const id = activeSpreadsheet.getId();
getLocale()
getLocale(): LocaleType
Get the locale of the workbook.
Returns
The locale of the workbook
Example
// The code below gets the locale of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const locale = activeSpreadsheet.getLocale();
getName()
getName(): string
Get the name of the workbook.
Returns
string
The name of the workbook.
Example
// The code below gets the name of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const name = activeSpreadsheet.getName();
getNumSheets()
getNumSheets(): number
Get the number of sheets in the workbook.
Returns
number
The number of sheets in the workbook
Example
// The code below gets the number of sheets in the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const numSheets = activeSpreadsheet.getNumSheets();
getPermission()
getPermission(): FPermission
Get the PermissionInstance.
Returns
- The PermissionInstance.
getPivotTableByCell()
getPivotTableByCell(
unitId,
subUnitId,
row,
col): FPivotTable
Parameters
Parameter | Type | Description |
---|---|---|
unitId | string | The unit id of workbook. |
subUnitId | string | The sheet id, which pivot table belongs to. |
row | number | The checked row. |
col | number | The checked column. |
Returns
The pivot table instance or undefined.
Description
Get the pivot table id by the cell.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook.getId();
const fSheet = fWorkbook.getActiveSheet();
const subUnitId = fSheet.getSheetId();
const pivotTable = fWorkbook.getPivotTableByCell(unitId, subUnitId, 1, 1);
if(pivotTable) {
pivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0);
}
getPivotTableById()
getPivotTableById(pivotTableId): FPivotTable
Parameters
Parameter | Type | Description |
---|---|---|
pivotTableId | string | The pivot table id. |
Returns
The pivot table instance or undefined.
Description
Get the pivot table by the pivot table id.
Example
const fWorkbook = univerAPI.getActiveWorkbook();
const mockId = 'abc123456';
const pivotTable = fWorkbook.getPivotTableById(mockId);
if(pivotTable) {
pivotTable.addField(1, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0);
}
getRegisteredRangeThemes()
getRegisteredRangeThemes(): string[]
Gets the registered range themes.
Returns
string
[]
The name list of registered range themes.
Example
// The code below gets the registered range themes
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const themes = activeSpreadsheet.getRegisteredRangeThemes();
console.log(themes);
getScrollStateBySheetId()
getScrollStateBySheetId(sheetId): any
Parameters
Parameter | Type |
---|---|
sheetId | string |
Returns
any
getSheetByName()
getSheetByName(name): FWorksheet
Get a worksheet by sheet name.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | The name of the sheet to get. |
Returns
The worksheet with given sheet name
Example
// The code below gets a worksheet by sheet name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheet = activeSpreadsheet.getSheetByName('Sheet1');
getSheetBySheetId()
getSheetBySheetId(sheetId): FWorksheet
Get a worksheet by sheet id.
Parameters
Parameter | Type | Description |
---|---|---|
sheetId | string | The id of the sheet to get. |
Returns
The worksheet with given sheet id
Example
// The code below gets a worksheet by sheet id
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheet = activeSpreadsheet.getSheetBySheetId('sheetId');
getSheets()
getSheets(): FWorksheet[]
Gets all the worksheets in this workbook
Returns
An array of all the worksheets in the workbook
Example
// The code below gets all the worksheets in the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheets = activeSpreadsheet.getSheets();
getSnapshot()
getSnapshot(): IWorkbookData
Returns
Workbook snapshot data
Deprecated
use ‘save’ instead.
Memberof
FWorkbook
Example
// The code below saves the workbook snapshot data
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const snapshot = activeSpreadsheet.getSnapshot();
getUrl()
getUrl(): string
Get the URL of the workbook.
Returns
string
The URL of the workbook
Example
// The code below gets the URL of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const url = activeSpreadsheet.getUrl();
getValidatorStatus()
getValidatorStatus(this): Promise<Record<..., ...>>
Get data validation validator status for current workbook.
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
Returns
Promise
<Record
<…, …>>
A promise that resolves to a matrix of validator status.
Example
univerAPI.getActiveWorkbook().getValidatorStatus().then((status) => { console.log(status) })
getWorkbook()
getWorkbook(): Workbook
Get the Workbook instance.
Returns
Workbook
The Workbook instance.
Example
// The code below gets the Workbook instance
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const workbook = activeSpreadsheet.getWorkbook();
insertDefinedName()
insertDefinedName(name, formulaOrRefString): FWorkbook
Insert a defined name.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | The name of the defined name to insert |
formulaOrRefString | string | The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert |
Returns
The current FWorkbook instance
Example
// The code below inserts a defined name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
insertDefinedNameBuilder()
insertDefinedNameBuilder(param): void
Insert a defined name by builder param.
Parameters
Parameter | Type | Description |
---|---|---|
param | ISetDefinedNameMutationParam | The param to insert the defined name |
Returns
void
Example
// The code below inserts a defined name by builder param
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const builder = univerAPI.newDefinedName();
const param = builder.setName('MyDefinedName').setRef('Sheet1!A1').build();
activeSpreadsheet.insertDefinedNameBuilder(param);
insertSheet()
insertSheet(sheetName?): FWorksheet
Inserts a new worksheet into the workbook. Using a default sheet name. The new sheet becomes the active sheet
Parameters
Parameter | Type | Description |
---|---|---|
sheetName ? | string | The name of the new sheet |
Returns
The new sheet
Example
// The code below inserts a new sheet into the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.insertSheet();
// The code below inserts a new sheet into the workbook, using a custom name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.insertSheet('MyNewSheet');
moveActiveSheet()
moveActiveSheet(index): FWorkbook
Move the active sheet to the specified index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | The index to move the active sheet to |
Returns
This workbook, for chaining
Example
// The code below moves the active sheet to the specified index
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.moveActiveSheet(1);
moveSheet()
moveSheet(sheet, index): FWorkbook
Move the sheet to the specified index.
Parameters
Parameter | Type | Description |
---|---|---|
sheet | FWorksheet | The sheet to move |
index | number | The index to move the sheet to |
Returns
This workbook, for chaining
Example
// The code below moves the sheet to the specified index
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheet = activeSpreadsheet.getActiveSheet();
activeSpreadsheet.moveSheet(sheet, 1);
newColor()
newColor(): ColorBuilder
Returns
ColorBuilder
Deprecated
use univerAPI.newColor()
as instead.
onBeforeAddDataValidation()
onBeforeAddDataValidation(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => { ... })
instead
onBeforeAddThreadComment()
onBeforeAddThreadComment(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.event.BeforeCommentAdd, () => {})
as instead
onBeforeCommandExecute()
onBeforeCommandExecute(callback): IDisposable
Register a callback that will be triggered before invoking a command targeting the Univer sheet.
Parameters
Parameter | Type | Description |
---|---|---|
callback | CommandListener | the callback. |
Returns
IDisposable
A function to dispose the listening.
Example
// The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.onBeforeCommandExecute((command) => {
console.log('Command executed:', command);
});
onBeforeDeleteAllDataValidation()
onBeforeDeleteAllDataValidation(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => { ... })
instead
onBeforeDeleteDataValidation()
onBeforeDeleteDataValidation(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => { ... })
instead
onBeforeDeleteThreadComment()
onBeforeDeleteThreadComment(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.event.BeforeCommentDelete, () => {})
as instead
onBeforeUpdateDataValidationCriteria()
onBeforeUpdateDataValidationCriteria(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => { ... })
instead
onBeforeUpdateDataValidationOptions()
onBeforeUpdateDataValidationOptions(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => { ... })
instead
onBeforeUpdateDataValidationRange()
onBeforeUpdateDataValidationRange(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => { ... })
instead
onBeforeUpdateThreadComment()
onBeforeUpdateThreadComment(this, callback): IDisposable
Parameters
Parameter | Type |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.event.BeforeCommentUpdate, () => {})
as instead
onCellClick()
onCellClick(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.CellClick, () => {})
instead
onCellHover()
onCellHover(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.CellHover, () => {})
instead
onCellPointerDown()
onCellPointerDown(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.CellPointerDown, () => {})
instead
onCellPointerMove()
onCellPointerMove(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell , event ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.CellPointerMove, () => {})
instead
onCellPointerUp()
onCellPointerUp(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.CellPointerUp, () => {})
instead
onCommandExecuted()
onCommandExecuted(callback): IDisposable
Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
Parameters
Parameter | Type | Description |
---|---|---|
callback | CommandListener | the callback. |
Returns
IDisposable
A function to dispose the listening.
Example
// The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.onCommandExecuted((command) => {
console.log('Command executed:', command);
});
onDataValidationChange()
onDataValidationChange(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (ruleChange ) => void |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.SheetDataValidationChanged, (event) => { ... })
instead
onDataValidationStatusChange()
onDataValidationStatusChange(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (statusChange ) => void |
Returns
IDisposable
Deprecated
Use univerAPI.addEvent(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => { ... })
instead
onDragOver()
onDragOver(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.DragOver, () => {})
instead
onDrop()
onDrop(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (cell ) => void |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.Event.Drop, () => {})
instead
onSelectionChange()
onSelectionChange(callback): IDisposable
Register a callback that will be triggered when the selection changes.
Parameters
Parameter | Type | Description |
---|---|---|
callback | (selections ) => void | The callback. |
Returns
IDisposable
A function to dispose the listening
onThreadCommentChange()
onThreadCommentChange(callback): IDisposable
Parameters
Parameter | Type |
---|---|
callback | (commentUpdate ) => … | … |
Returns
IDisposable
Deprecated
use univerAPI.addEvent(univerAPI.event.CommentUpdated, () => {})
as instead
openDialog()
openDialog(dialog): IDisposable
Open a dialog.
Parameters
Parameter | Type | Description |
---|---|---|
dialog | IDialogPartMethodOptions | the dialog options |
Returns
IDisposable
the disposable object
Deprecated
openPrintDialog()
openPrintDialog(): void
open print dialog
Returns
void
Example
univerAPI.getActiveWorkbook().openPrintDialog();
openSiderbar()
openSiderbar(params): IDisposable
Open a sidebar.
Parameters
Parameter | Type | Description |
---|---|---|
params | ISidebarMethodOptions | the sidebar options |
Returns
IDisposable
the disposable object
Deprecated
parseSheetHyperlink()
parseSheetHyperlink(this, hyperlink): ISheetHyperLinkInfo
Parse the hyperlink string to get the hyperlink info.
Parameters
Parameter | Type | Description |
---|---|---|
this | FWorkbook | - |
hyperlink | string | the hyperlink string |
Returns
ISheetHyperLinkInfo
the hyperlink info
Example
univerAPI.getActiveWorkbook().parseSheetHyperlink('#gid=sheet_Id&range=F6')
print()
print(): void
using current print config and render config to print
Returns
void
Example
univerAPI.getActiveWorkbook().print();
redo()
redo(): FWorkbook
Redo the last undone action.
Returns
A promise that resolves to true if the redo was successful, false otherwise.
Example
// The code below redoes the last undone action
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.redo();
registerRangeTheme()
registerRangeTheme(rangeThemeStyle): void
Register a custom range theme style.
Parameters
Parameter | Type | Description |
---|---|---|
rangeThemeStyle | RangeThemeStyle | The range theme style to register |
Returns
void
Example
// import {RangeThemeStyle} from '@univerjs/sheets';
const fWorkbook = univerAPI.getActiveWorkbook();
const rangeThemeStyle = new RangeThemeStyle('MyTheme');
rangeThemeStyle.setSecondRowStyle({
bg: {
rgb: 'rgb(214,231,241)',
},
});
fWorkbook.registerRangeTheme(rangeThemeStyle);
save()
save(): IWorkbookData
Save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
Returns
Workbook snapshot data
Example
// The code below saves the workbook snapshot data
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const snapshot = activeSpreadsheet.save();
saveScreenshotToClipboard()
saveScreenshotToClipboard(): Promise<boolean>
save screenshot of current range to clipboard
Returns
Promise
<boolean
>
Example
univerAPI.getActiveWorkbook().saveScreenshotToClipboard();
setActiveRange()
setActiveRange(range): FWorkbook
Sets the selection region for active sheet.
Parameters
Parameter | Type | Description |
---|---|---|
range | FRange | The range to set as the active selection. |
Returns
FWorkbook instance
setActiveSheet()
setActiveSheet(sheet): FWorksheet
Sets the given worksheet to be the active worksheet in the workbook.
Parameters
Parameter | Type | Description |
---|---|---|
sheet | string | FWorksheet | The worksheet to set as the active worksheet. |
Returns
The active worksheet
Example
// The code below sets the given worksheet to be the active worksheet
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const sheet = activeSpreadsheet.getSheetByName('Sheet1');
activeSpreadsheet.setActiveSheet(sheet);
setCustomMetadata()
setCustomMetadata(custom): FWorkbook
Set custom metadata of workbook
Parameters
Parameter | Type | Description |
---|---|---|
custom | CustomData | custom metadata |
Returns
FWorkbook
Example
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setCustomMetadata({ key: 'value' });
setEditable()
setEditable(value): FWorkbook
Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.
Parameters
Parameter | Type | Description |
---|---|---|
value | boolean | editable value want to set |
Returns
FWorkbook instance
setLocale()
setLocale(locale): void
Parameters
Parameter | Type | Description |
---|---|---|
locale | LocaleType | The locale to set |
Returns
void
Deprecated
use setSpreadsheetLocale instead.
setName()
setName(name): void
Set the name of the workbook.
Parameters
Parameter | Type | Description |
---|---|---|
name | string | The new name of the workbook. |
Returns
void
Example
// The code below sets the name of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.setName('MyWorkbook');
setNumfmtLocal()
setNumfmtLocal(local): FWorkbook
Parameters
Parameter | Type | Description |
---|---|---|
local | LocaleTag | zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi |
Returns
{FWorkbook}
Example
univerAPI.getActiveWorkbook().setNumfmtLocal('en')
Memberof
IFWorkbookNumfmtMixin
setSpreadsheetLocale()
setSpreadsheetLocale(locale): FWorkbook
Set the locale of the workbook.
Parameters
Parameter | Type | Description |
---|---|---|
locale | LocaleType | The locale to set |
Returns
This workbook, for chaining
Example
// The code below sets the locale of the workbook
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.setLocale(LocaleType.EN_US);
showSelection()
showSelection(): FWorkbook
Set selection visible.
Returns
Example
univerAPI.getActiveWorkbook().showSelection();
startEditing()
startEditing(): boolean
Start the editing process
Returns
boolean
A boolean value
Example
univerAPI.getActiveWorkbook().startEditing();
startZenEditingAsync()
startZenEditingAsync(): Promise<boolean>
Start the zen editing process
Returns
Promise
<boolean
>
A promise that resolves to a boolean indicating whether the zen editing process was started successfully.
Example
univerAPI.getActiveWorkbook().startZenEditingAsync();
transparentSelection()
transparentSelection(): FWorkbook
Set selection invisible, Unlike disableSelection, selection still works, you just can not see them.
Returns
Example
univerAPI.getActiveWorkbook().transparentSelection();
undo()
undo(): FWorkbook
Undo the last action.
Returns
A promise that resolves to true if the undo was successful, false otherwise.
Example
// The code below undoes the last action
const activeSpreadsheet = univerAPI.getActiveWorkbook();
activeSpreadsheet.undo();
unregisterRangeTheme()
unregisterRangeTheme(themeName): void
Unregister a custom range theme style.
Parameters
Parameter | Type | Description |
---|---|---|
themeName | string | The name of the theme to unregister |
Returns
void
Example
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.unregisterRangeTheme('MyTheme');
updateDefinedNameBuilder()
updateDefinedNameBuilder(param): void
Update the defined name with the given name.
Parameters
Parameter | Type | Description |
---|---|---|
param | ISetDefinedNameMutationParam | The param to insert the defined name |
Returns
void
Example
// The code below updates the defined name with the given name
const activeSpreadsheet = univerAPI.getActiveWorkbook();
const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();
builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();
activeSpreadsheet.updateDefinedNameBuilder(param);
updatePrintConfig()
updatePrintConfig(config): FWorkbook
update print config, include print area, page-setting, scale, freeze, margin, and etc.
Parameters
Parameter | Type | Description |
---|---|---|
config | ISheetPrintLayoutConfig |
Returns
Example
univerAPI.getActiveWorkbook().updatePrintConfig({
area: PrintArea.SHEET,
subUnitIds: ['Sheet1'],
id: 'Sheet1',
pageSize: PrintPaperSize.A4,
scale: PrintScale.FIT_PAGE,
freeze: PrintFreeze.NONE,
margin: {
top: 0,
bottom: 0,
left: 0,
right: 0,
},
});
updatePrintRenderConfig()
updatePrintRenderConfig(config): FWorkbook
update print render config, include print header-footer setting, alignment, gridline, and etc.
Parameters
Parameter | Type | Description |
---|---|---|
config | ISheetPrintRenderConfig |
Returns
Example
univerAPI.getActiveWorkbook().updatePrintRenderConfig({
headerFooter: PrintHeaderFooter.NONE,
alignment: PrintAlignment.CENTER,
gridline: PrintGridline.NONE,
});