类: FWorkbook
Facade API object bounded to a workbook. It provides a set of methods to interact with the workbook.
继承
FBaseInitialable
.IFWorkbookNumfmtMixin
.IFWorkbookHyperlinkMixin
.IFWorkbookDataValidationMixin
.IFWorkbookConditionalFormattingMixin
.IFWorkbookThreadCommentMixin
.IFWorkbookSheetsPivotMixin
.IFWorkbookSheetsUIMixin
.IFWorkbookSheetsZenEditorMixin
.IFWorkbookSheetsPrintMixin
属性
属性 | 修饰符 | 类型 |
---|---|---|
|
|
方法
addPivotTable()
addPivotTable(
sourceInfo,
positionType,
anchorCellInfo): Promise<FPivotTable>
参数
参数 | 类型 | 描述 |
---|---|---|
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. |
返回
Promise
<FPivotTable
>
The added pivot table id.
Description
Add a pivot table to the Workbook.
示例
// 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
返回
Promise
<boolean
>
Whether the comments are cleared successfully.
示例
const workbook = univerAPI.getActiveWorkbook();
const success = await workbook.clearComments();
closePrintDialog()
closePrintDialog(): void
close print dialog
返回
void
示例
univerAPI.getActiveWorkbook().closePrintDialog();
create()
create(
name,
rows,
column): FWorksheet
Create a new worksheet and returns a handle to it.
参数
参数 | 类型 | 描述 |
---|---|---|
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 |
返回
The new created sheet
示例
// The code below creates a new sheet
const fWorkbook = univerAPI.getActiveWorkbook();
const newSheet = fWorkbook.create('MyNewSheet', 10, 10);
console.log(newSheet);
createRangeThemeStyle()
createRangeThemeStyle(themeName, themeStyleJson?): RangeThemeStyle
Create a range theme style.
参数
参数 | 类型 | 描述 |
---|---|---|
themeName | string | The name of the theme to register |
themeStyleJson ? | Omit <IRangeThemeStyleJSON , "name" > | The theme style json to register |
返回
RangeThemeStyle
- The created range theme style
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const rangeThemeStyle = fWorkbook.createRangeThemeStyle('MyTheme', {
secondRowStyle: {
bg: {
rgb: 'rgb(214,231,241)',
},
},
});
console.log(rangeThemeStyle);
createSheetHyperlink()
createSheetHyperlink(
this,
sheetId,
range?): string
参数
参数 | 类型 |
---|---|
this | FWorkbook |
sheetId | string |
range ? | string | IRange |
返回
string
已被弃用
use getUrl
method in FRange
or FWorksheet
instead.
deleteActiveSheet()
deleteActiveSheet(): boolean
Deletes the currently active sheet.
返回
boolean
true if the sheet was deleted, false otherwise
示例
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.deleteActiveSheet();
deleteDefinedName()
deleteDefinedName(name): boolean
Delete the defined name with the given name.
参数
参数 | 类型 | 描述 |
---|---|---|
name | string | The name of the defined name to delete |
返回
boolean
true if the defined name was deleted, false otherwise
示例
// The code below deletes the defined name with the given name
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.deleteDefinedName('MyDefinedName');
deleteSheet()
deleteSheet(sheet): boolean
Deletes the specified worksheet.
参数
参数 | 类型 | 描述 |
---|---|---|
sheet | string | FWorksheet | The worksheet to delete. |
返回
boolean
True if the worksheet was deleted, false otherwise.
示例
// The code below deletes the specified worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheets()[1];
fWorkbook.deleteSheet(sheet);
disableSelection()
disableSelection(): FWorkbook
Disable selection. After disabled, there would be no response for selection.
返回
FWorkbook instance
示例
univerAPI.getActiveWorkbook().disableSelection();
duplicateActiveSheet()
duplicateActiveSheet(): FWorksheet
Duplicates the active sheet.
返回
The duplicated worksheet
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const duplicatedSheet = fWorkbook.duplicateActiveSheet();
console.log(duplicatedSheet);
duplicateSheet()
duplicateSheet(sheet): FWorksheet
Duplicates the given worksheet.
参数
参数 | 类型 | 描述 |
---|---|---|
sheet | FWorksheet | The worksheet to duplicate. |
返回
The duplicated worksheet
示例
// The code below duplicates the given worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const activeSheet = fWorkbook.getActiveSheet();
const duplicatedSheet = fWorkbook.duplicateSheet(activeSheet);
console.log(duplicatedSheet);
enableSelection()
enableSelection(): FWorkbook
Enable selection. After this you can select range.
返回
示例
univerAPI.getActiveWorkbook().enableSelection();
endEditing()
endEditing(save?): Promise<boolean>
参数
参数 | 类型 |
---|---|
save ? | boolean |
返回
Promise
<boolean
>
已被弃用
Use endEditingAsync
as instead
endEditingAsync()
endEditingAsync(save?): Promise<boolean>
参数
参数 | 类型 | 描述 |
---|---|---|
save ? | boolean | Whether to save the changes, default is true |
返回
Promise
<boolean
>
A promise that resolves to a boolean value
Async
End the editing process
示例
await univerAPI.getActiveWorkbook().endEditingAsync(false);
endZenEditingAsync()
endZenEditingAsync(save?): Promise<boolean>
End the zen editing process
参数
参数 | 类型 | 描述 |
---|---|---|
save ? | boolean | Whether to save the changes, default is true |
返回
Promise
<boolean
>
A promise that resolves to a boolean indicating whether the zen editing process was ended successfully.
Async
示例
univerAPI.getActiveWorkbook().endZenEditingAsync(false);
getActiveRange()
getActiveRange(): FRange
Returns the selected range in the active sheet, or null if there is no active range.
返回
The active range
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const activeRange = fWorkbook.getActiveRange();
console.log(activeRange);
getActiveSheet()
getActiveSheet(): FWorksheet
Get the active sheet of the workbook.
返回
The active sheet of the workbook
示例
// The code below gets the active sheet of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
console.log(fWorksheet);
getComments()
getComments(): FThreadComment[]
Get all comments in the current sheet
返回
all comments in the current sheet
示例
const workbook = univerAPI.getActiveWorkbook();
const comments = workbook.getComments();
getCustomMetadata()
getCustomMetadata(): CustomData
Get custom metadata of workbook
返回
custom metadata
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const custom = fWorkbook.getCustomMetadata();
console.log(custom);
getDefinedName()
getDefinedName(name): FDefinedName
Get the defined name by name.
参数
参数 | 类型 | 描述 |
---|---|---|
name | string | The name of the defined name to get |
返回
The defined name with the given name
示例
// The code below gets the defined name by name
const fWorkbook = univerAPI.getActiveWorkbook();
const definedName = fWorkbook.getDefinedName('MyDefinedName');
console.log(definedName);
getDefinedNames()
getDefinedNames(): FDefinedName[]
Get all the defined names in the workbook.
返回
All the defined names in the workbook
示例
// The code below gets all the defined names in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNames = fWorkbook.getDefinedNames();
console.log(definedNames);
getId()
getId(): string
Get the id of the workbook.
返回
string
The id of the workbook.
示例
// The code below gets the id of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook.getId();
console.log(unitId);
getLocale()
getLocale(): LocaleType
Get the locale of the workbook.
返回
The locale of the workbook
示例
// The code below gets the locale of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getLocale());
getName()
getName(): string
Get the name of the workbook.
返回
string
The name of the workbook.
示例
// The code below gets the name of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const name = fWorkbook.getName();
console.log(name);
getNumSheets()
getNumSheets(): number
Get the number of sheets in the workbook.
返回
number
The number of sheets in the workbook
示例
// The code below gets the number of sheets in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook.getNumSheets());
getPermission()
getPermission(): FPermission
Get the PermissionInstance.
返回
- The PermissionInstance.
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const permission = fWorkbook.getPermission();
console.log(permission);
getPivotTableByCell()
getPivotTableByCell(
unitId,
subUnitId,
row,
col): FPivotTable
参数
参数 | 类型 | 描述 |
---|---|---|
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. |
返回
The pivot table instance or undefined.
Description
Get the pivot table id by the cell.
示例
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
参数
参数 | 类型 | 描述 |
---|---|---|
pivotTableId | string | The pivot table id. |
返回
The pivot table instance or undefined.
Description
Get the pivot table by the pivot table id.
示例
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.
返回
string
[]
The name list of registered range themes.
示例
// The code below gets the registered range themes
const fWorkbook = univerAPI.getActiveWorkbook();
const themes = fWorkbook.getRegisteredRangeThemes();
console.log(themes);
getScrollStateBySheetId()
getScrollStateBySheetId(sheetId): any
参数
参数 | 类型 |
---|---|
sheetId | string |
返回
any
getSheetByName()
getSheetByName(name): FWorksheet
Get a worksheet by sheet name.
参数
参数 | 类型 | 描述 |
---|---|---|
name | string | The name of the sheet to get. |
返回
The worksheet with given sheet name
示例
// The code below gets a worksheet by sheet name
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheetByName('Sheet1');
console.log(sheet);
getSheetBySheetId()
getSheetBySheetId(sheetId): FWorksheet
Get a worksheet by sheet id.
参数
参数 | 类型 | 描述 |
---|---|---|
sheetId | string | The id of the sheet to get. |
返回
The worksheet with given sheet id
示例
// The code below gets a worksheet by sheet id
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheetBySheetId('sheetId');
console.log(sheet);
getSheets()
getSheets(): FWorksheet[]
Gets all the worksheets in this workbook
返回
An array of all the worksheets in the workbook
示例
// The code below gets all the worksheets in the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const sheets = fWorkbook.getSheets();
console.log(sheets);
getSnapshot()
getSnapshot(): IWorkbookData
返回
Workbook snapshot data
已被弃用
use ‘save’ instead.
Memberof
FWorkbook
示例
// 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.
返回
string
The URL of the workbook
示例
// The code below gets the URL of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
const url = fWorkbook.getUrl();
console.log(url);
getValidatorStatus()
getValidatorStatus(): Promise<Record<..., ...>>
Get data validation validator status for current workbook.
返回
Promise
<Record
<…, …>>
A promise that resolves to a matrix of validator status.
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const status = await fWorkbook.getValidatorStatus();
console.log(status);
getWorkbook()
getWorkbook(): Workbook
Get the Workbook instance.
返回
Workbook
The Workbook instance.
示例
// The code below gets the Workbook instance
const fWorkbook = univerAPI.getActiveWorkbook();
const workbook = fWorkbook.getWorkbook();
console.log(workbook);
insertDefinedName()
insertDefinedName(name, formulaOrRefString): FWorkbook
Insert a defined name.
参数
参数 | 类型 | 描述 |
---|---|---|
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 |
返回
The current FWorkbook instance
示例
// The code below inserts a defined name
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.insertDefinedName('MyDefinedName', 'Sheet1!A1');
insertDefinedNameBuilder()
insertDefinedNameBuilder(param): void
Insert a defined name by builder param.
参数
参数 | 类型 | 描述 |
---|---|---|
param | ISetDefinedNameMutationParam | The param to insert the defined name |
返回
void
示例
// The code below inserts a defined name by builder param
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameBuilder = univerAPI.newDefinedName()
.setRef('Sheet1!$A$1')
.setName('MyDefinedName')
.setComment('This is a comment')
.build();
fWorkbook.insertDefinedNameBuilder(definedNameBuilder);
insertSheet()
insertSheet(sheetName?): FWorksheet
Inserts a new worksheet into the workbook. Using a default sheet name. The new sheet becomes the active sheet
参数
参数 | 类型 | 描述 |
---|---|---|
sheetName ? | string | The name of the new sheet |
返回
The new sheet
示例
// The code below inserts a new sheet into the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.insertSheet();
// The code below inserts a new sheet into the workbook, using a custom name
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.insertSheet('MyNewSheet');
moveActiveSheet()
moveActiveSheet(index): FWorkbook
Move the active sheet to the specified index.
参数
参数 | 类型 | 描述 |
---|---|---|
index | number | The index to move the active sheet to |
返回
This workbook, for chaining
示例
// The code below moves the active sheet to the specified index
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.moveActiveSheet(1);
moveSheet()
moveSheet(sheet, index): FWorkbook
Move the sheet to the specified index.
参数
参数 | 类型 | 描述 |
---|---|---|
sheet | FWorksheet | The sheet to move |
index | number | The index to move the sheet to |
返回
This workbook, for chaining
示例
// The code below moves the sheet to the specified index
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getActiveSheet();
fWorkbook.moveSheet(sheet, 1);
newColor()
newColor(): ColorBuilder
返回
ColorBuilder
已被弃用
use univerAPI.newColor()
as instead.
onBeforeAddDataValidation()
onBeforeAddDataValidation(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationAdd, (event) => { ... })
instead
onBeforeAddThreadComment()
onBeforeAddThreadComment(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
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.
参数
参数 | 类型 | 描述 |
---|---|---|
callback | CommandListener | the callback. |
返回
IDisposable
A function to dispose the listening.
示例
// The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.onBeforeCommandExecute((command) => {
console.log('Before command execute:', command);
});
onBeforeDeleteAllDataValidation()
onBeforeDeleteAllDataValidation(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDeleteAll, (event) => { ... })
instead
onBeforeDeleteDataValidation()
onBeforeDeleteDataValidation(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationDelete, (event) => { ... })
instead
onBeforeDeleteThreadComment()
onBeforeDeleteThreadComment(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.BeforeCommentDelete, () => {})
as instead
onBeforeUpdateDataValidationCriteria()
onBeforeUpdateDataValidationCriteria(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationCriteriaUpdate, (event) => { ... })
instead
onBeforeUpdateDataValidationOptions()
onBeforeUpdateDataValidationOptions(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationOptionsUpdate, (event) => { ... })
instead
onBeforeUpdateDataValidationRange()
onBeforeUpdateDataValidationRange(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.BeforeSheetDataValidationRangeUpdate, (event) => { ... })
instead
onBeforeUpdateThreadComment()
onBeforeUpdateThreadComment(this, callback): IDisposable
参数
参数 | 类型 |
---|---|
this | FWorkbook |
callback | (params , options ) => … | … |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.BeforeCommentUpdate, () => {})
as instead
onCellClick()
onCellClick(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CellClick, () => {})
instead
onCellHover()
onCellHover(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CellHover, () => {})
instead
onCellPointerDown()
onCellPointerDown(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CellPointerDown, () => {})
instead
onCellPointerMove()
onCellPointerMove(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell , event ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CellPointerMove, () => {})
instead
onCellPointerUp()
onCellPointerUp(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
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.
参数
参数 | 类型 | 描述 |
---|---|---|
callback | CommandListener | the callback. |
返回
IDisposable
A function to dispose the listening.
示例
// The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.onCommandExecuted((command) => {
console.log('Command executed:', command);
});
onDataValidationChange()
onDataValidationChange(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (ruleChange ) => void |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.SheetDataValidationChanged, (event) => { ... })
instead
onDataValidationStatusChange()
onDataValidationStatusChange(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (statusChange ) => void |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.SheetDataValidatorStatusChanged, (event) => { ... })
instead
onDragOver()
onDragOver(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.DragOver, () => {})
instead
onDrop()
onDrop(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (cell ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.Drop, () => {})
instead
onSelectionChange()
onSelectionChange(callback): IDisposable
Register a callback that will be triggered when the selection changes.
参数
参数 | 类型 | 描述 |
---|---|---|
callback | (selections ) => void | The callback. |
返回
IDisposable
A function to dispose the listening
示例
// The code below registers a callback that will be triggered when the selection changes
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.onSelectionChange((selections) => {
console.log('Selection changed:', selections);
});
onThreadCommentChange()
onThreadCommentChange(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (commentUpdate ) => … | … |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommentUpdated, () => {})
as instead
openDialog()
openDialog(dialog): IDisposable
Open a dialog.
参数
参数 | 类型 | 描述 |
---|---|---|
dialog | IDialogPartMethodOptions | the dialog options |
返回
IDisposable
the disposable object
已被弃用
openPrintDialog()
openPrintDialog(): void
open print dialog
返回
void
示例
univerAPI.getActiveWorkbook().openPrintDialog();
openSiderbar()
openSiderbar(params): IDisposable
Open a sidebar.
参数
参数 | 类型 | 描述 |
---|---|---|
params | ISidebarMethodOptions | the sidebar options |
返回
IDisposable
the disposable object
已被弃用
parseSheetHyperlink()
parseSheetHyperlink(this, hyperlink): ISheetHyperLinkInfo
Parse the hyperlink string to get the hyperlink info.
参数
参数 | 类型 | 描述 |
---|---|---|
this | FWorkbook | - |
hyperlink | string | The hyperlink string. |
返回
ISheetHyperLinkInfo
The hyperlink info.
示例
// Create a hyperlink to the range A1:D10 of the current sheet
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:D10');
const hyperlink = fRange.getUrl();
// Parse the hyperlink
const hyperlinkInfo = fWorkbook.parseSheetHyperlink(hyperlink);
console.log(hyperlinkInfo);
print()
print(): void
using current print config and render config to print
返回
void
示例
univerAPI.getActiveWorkbook().print();
redo()
redo(): FWorkbook
Redo the last undone action.
返回
A promise that resolves to true if the redo was successful, false otherwise.
示例
// The code below redoes the last undone action
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.redo();
registerRangeTheme()
registerRangeTheme(rangeThemeStyle): void
Register a custom range theme style.
参数
参数 | 类型 | 描述 |
---|---|---|
rangeThemeStyle | RangeThemeStyle | The range theme style to register |
返回
void
示例
// import {RangeThemeStyle} from '@univerjs/sheets';
const fWorkbook = univerAPI.getActiveWorkbook();
const rangeThemeStyle = fWorkbook.createRangeThemeStyle('MyTheme', {
secondRowStyle: {
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.
返回
Workbook snapshot data
示例
// The code below saves the workbook snapshot data
const fWorkbook = univerAPI.getActiveWorkbook();
const snapshot = fWorkbook.save();
console.log(snapshot);
saveScreenshotToClipboard()
saveScreenshotToClipboard(): Promise<boolean>
save screenshot of current range to clipboard
返回
Promise
<boolean
>
示例
univerAPI.getActiveWorkbook().saveScreenshotToClipboard();
setActiveRange()
setActiveRange(range): FWorkbook
Sets the selection region for active sheet.
参数
参数 | 类型 | 描述 |
---|---|---|
range | FRange | The range to set as the active selection. |
返回
FWorkbook instance
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const range = fWorkbook.getActiveSheet().getRange('A10:B10');
fWorkbook.setActiveRange(range);
setActiveSheet()
setActiveSheet(sheet): FWorksheet
Sets the given worksheet to be the active worksheet in the workbook.
参数
参数 | 类型 | 描述 |
---|---|---|
sheet | string | FWorksheet | The worksheet to set as the active worksheet. |
返回
The active worksheet
示例
// The code below sets the given worksheet to be the active worksheet
const fWorkbook = univerAPI.getActiveWorkbook();
const sheet = fWorkbook.getSheets()[1];
fWorkbook.setActiveSheet(sheet);
setCustomMetadata()
setCustomMetadata(custom): FWorkbook
Set custom metadata of workbook
参数
参数 | 类型 | 描述 |
---|---|---|
custom | CustomData | custom metadata |
返回
FWorkbook
示例
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.
参数
参数 | 类型 | 描述 |
---|---|---|
value | boolean | editable value want to set |
返回
FWorkbook instance
示例
// The code below sets the editing permissions of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setEditable(false);
setLocale()
setLocale(locale): void
参数
参数 | 类型 | 描述 |
---|---|---|
locale | LocaleType | The locale to set |
返回
void
已被弃用
use setSpreadsheetLocale
instead.
setName()
setName(name): void
Set the name of the workbook.
参数
参数 | 类型 | 描述 |
---|---|---|
name | string | The new name of the workbook. |
返回
void
示例
// The code below sets the name of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setName('MyWorkbook');
setNumfmtLocal()
setNumfmtLocal(local): FWorkbook
Set the locale for number formatting.
参数
参数 | 类型 | 描述 |
---|---|---|
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 |
返回
The FWorkbook instance for chaining.
Memberof
IFWorkbookNumfmtMixin
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1');
fRange.setValue(1234.567).setNumberFormat('#,##0.00');
// Set the locale en_US for number formatting.
fWorkbook.setNumfmtLocal('en_US');
console.log(fRange.getValue()); // 1,234.57
// Set the locale de_DE for number formatting.
fWorkbook.setNumfmtLocal('de_DE');
console.log(fRange.getValue()); // 1.234,57
继承自
IFWorkbookNumfmtMixin
.setNumfmtLocal
setSpreadsheetLocale()
setSpreadsheetLocale(locale): FWorkbook
Set the locale of the workbook.
参数
参数 | 类型 | 描述 |
---|---|---|
locale | LocaleType | The locale to set |
返回
This workbook, for chaining
示例
// The code below sets the locale of the workbook
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.setSpreadsheetLocale(univerAPI.Enum.LocaleType.EN_US);
console.log(fWorkbook.getLocale());
showSelection()
showSelection(): FWorkbook
Set selection visible.
返回
示例
univerAPI.getActiveWorkbook().showSelection();
startEditing()
startEditing(): boolean
Start the editing process
返回
boolean
A boolean value
示例
univerAPI.getActiveWorkbook().startEditing();
startZenEditingAsync()
startZenEditingAsync(): Promise<boolean>
Start the zen editing process
返回
Promise
<boolean
>
A promise that resolves to a boolean indicating whether the zen editing process was started successfully.
示例
univerAPI.getActiveWorkbook().startZenEditingAsync();
transparentSelection()
transparentSelection(): FWorkbook
Set selection invisible, Unlike disableSelection, selection still works, you just can not see them.
返回
示例
univerAPI.getActiveWorkbook().transparentSelection();
undo()
undo(): FWorkbook
Undo the last action.
返回
A promise that resolves to true if the undo was successful, false otherwise.
示例
// The code below undoes the last action
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.undo();
unregisterRangeTheme()
unregisterRangeTheme(themeName): void
Unregister a custom range theme style.
参数
参数 | 类型 | 描述 |
---|---|---|
themeName | string | The name of the theme to unregister |
返回
void
示例
const fWorkbook = univerAPI.getActiveWorkbook();
fWorkbook.unregisterRangeTheme('MyTheme');
updateDefinedNameBuilder()
updateDefinedNameBuilder(param): void
Update the defined name with the given name.
参数
参数 | 类型 | 描述 |
---|---|---|
param | ISetDefinedNameMutationParam | The param to insert the defined name |
返回
void
示例
// The code below updates the defined name with the given name
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameBuilder = fWorkbook.getDefinedName('MyDefinedName').toBuilder();
const param = definedNameBuilder.setRef('Sheet1!A2')
.setName('NewDefinedName')
.build();
fWorkbook.updateDefinedNameBuilder(param);
updatePrintConfig()
updatePrintConfig(config): FWorkbook
update print config, include print area, page-setting, scale, freeze, margin, and etc.
参数
参数 | 类型 | 描述 |
---|---|---|
config | ISheetPrintLayoutConfig |
返回
示例
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.
参数
参数 | 类型 | 描述 |
---|---|---|
config | ISheetPrintRenderConfig |
返回
示例
univerAPI.getActiveWorkbook().updatePrintRenderConfig({
headerFooter: PrintHeaderFooter.NONE,
alignment: PrintAlignment.CENTER,
gridline: PrintGridline.NONE,
});