类: FUniver
The root Facade API object to interact with Univer. Please use newAPI
static method
to create a new instance.
继承
IFUniverNetworkMixin
.IFUniverNetworkMixin
.IFUniverEngineFormulaMixin
.IFUniverSheetsMixin
.IFUniverSheetsFormulaMixin
.IFUnvierDataValidationMixin
.IFUniverCommentMixin
.IFUniverCollaborationClientMixin
.IFUniverPivotTableEventMixin
.IFUniverDocsUIMixin
.IFUniverUIMixin
.IFUniverSheetsUIMixin
.IFUniverFindReplaceMixin
.IFUniverCrosshairHighlightMixin
.IFUniverWatermarkMixin
.IFUniverSheetsZenEditorMixin
.IFUniverNodeRuntimeMixin
.IFUniverExchangeClientMixin
属性
属性 | 修饰符 | 类型 | 描述 |
---|---|---|---|
|
|
Get the available built-in colors for the crosshair highlight. |
访问器
Enum
Getter 签名
get Enum(): FEnum
返回
Event
Getter 签名
get Event(): FEventName
返回
Util
Getter 签名
get Util(): FUtil
返回
FUtil
方法
addEvent()
addEvent<T>(event, callback): IDisposable
Add an event listener
类型参数
类型参数 |
---|
T extends keyof IEventParamConfig |
参数
参数 | 类型 | 描述 |
---|---|---|
event | T | key of event |
callback | (params ) => void | callback when event triggered |
返回
IDisposable
The Disposable instance, for remove the listener
示例
// Add life cycle changed event listener
const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (params) => {
const { stage } = params;
console.log('life cycle changed', params);
});
// Remove the event listener, use `disposable.dispose()`
addWatermark()
调用签名
addWatermark(type, config): FUniver
Adds a watermark to the unit. Supports both text and image watermarks based on the specified type.
参数
参数 | 类型 | 描述 |
---|---|---|
type | Text | The type of watermark to add. Can be either ‘Text’ or ‘Image’. |
config | ITextWatermarkConfig | The configuration object for the watermark. - If the type is ‘Text’, the config should follow the ITextWatermarkConfig interface. - If the type is ‘Image’, the config should follow the IImageWatermarkConfig interface. |
返回
抛出
Throws an error if the watermark type is unknown.
调用签名
addWatermark(type, config): FUniver
参数
参数 | 类型 |
---|---|
type | Image |
config | IImageWatermarkConfig |
返回
调用签名
addWatermark(type, config): FUniver
参数
参数 | 类型 |
---|---|
type | any |
config | any |
返回
copy()
copy(): Promise<boolean>
Copy the current selected content of the currently focused unit into your system clipboard.
返回
Promise
<boolean
>
createMenu()
createMenu(menuItem): FMenu
Create a menu build object. You can insert new menus into the UI.
参数
参数 | 类型 | 描述 |
---|---|---|
menuItem | IFacadeMenuItem | the menu item |
返回
the FMenu object
示例
univerAPI.createMenu({
id: 'custom-menu',
title: 'Custom Menu',
action: () => {},
}).appendTo('ribbon.start.others');
createSubmenu()
createSubmenu(submenuItem): FSubmenu
Create a menu that contains submenus, and later you can append this menu and its submenus to the UI.
参数
参数 | 类型 | 描述 |
---|---|---|
submenuItem | IFacadeSubmenuItem | the submenu item |
返回
the FSubmenu object
示例
univerAPI.createSubmenu({ id: 'custom-submenu', title: 'Custom Submenu' })
.addSubmenu(univerAPI.createSubmenu({ id: 'submenu-nested', title: 'Nested Submenu' })
.addSubmenu(univerAPI.createMenu({ id: 'submenu-nested-1', title: 'Item 1', action: () => {} }))
.addSeparator()
.addSubmenu(univerAPI.createMenu({ id: 'submenu-nested-2', title: 'Item 2', action: () => {} }))
)
.appendTo('contextMenu.others');
createTextFinderAsync()
createTextFinderAsync(text): Promise<FTextFinder>
Create a text-finder for the current univer.
参数
参数 | 类型 | 描述 |
---|---|---|
text | string | The text to find. |
返回
Promise
<FTextFinder
>
A promise that resolves to the text-finder instance.
示例
// Assume the current sheet is empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:D10');
fRange.setValues([
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7],
[5, 6, 7, 8],
[6, 7, 8, 9],
[7, 8, 9, 10],
[8, 9, 10, 11],
[9, 10, 11, 12],
[10, 11, 12, 13]
]);
// Create a text-finder to find the text '5'.
const textFinder = await univerAPI.createTextFinderAsync('5');
// Find all cells that contain the text '5'.
const matchCells = textFinder.findAll();
matchCells.forEach((cell) => {
console.log(cell.getA1Notation()); // D2, C3, B4, A5
});
createUniverDoc()
createUniverDoc(data): FDocument
Create a new document and get the API handler of that document.
参数
参数 | 类型 | 描述 |
---|---|---|
data | Partial <IDocumentData > | The snapshot of the document. |
返回
FDocument API instance.
createUniverSheet()
createUniverSheet(data): FWorkbook
参数
参数 | 类型 |
---|---|
data | Partial <IWorkbookData > |
返回
已被弃用
use univerAPI.createWorkbook
instead.
createWorkbook()
createWorkbook(data, options?): FWorkbook
Create a new spreadsheet and get the API handler of that spreadsheet.
参数
参数 | 类型 | 描述 |
---|---|---|
data | Partial <IWorkbookData > | The snapshot of the spreadsheet. |
options ? | ICreateUnitOptions | The options of creating the spreadsheet. |
返回
FWorkbook API instance.
示例
const fWorkbook = univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' });
console.log(fWorkbook);
Add you can make the workbook not as the active workbook by setting options:
const fWorkbook = univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' }, { makeCurrent: false });
console.log(fWorkbook);
customizeColumnHeader()
customizeColumnHeader(cfg): void
参数
参数 | 类型 | 描述 |
---|---|---|
cfg | IColumnsHeaderCfgParam | The configuration of the column header. |
返回
void
已被弃用
use same API in FWorkSheet. Customize the column header of the spreadsheet.
示例
univerAPI.customizeColumnHeader({ headerStyle: { fontColor: '#fff', size: 40, backgroundColor: '#4e69ee', fontSize: 9 }, columnsCfg: ['MokaII', undefined, null, { text: 'Size', textAlign: 'left' }] });
customizeRowHeader()
customizeRowHeader(cfg): void
参数
参数 | 类型 | 描述 |
---|---|---|
cfg | IRowsHeaderCfgParam | The configuration of the row header. |
返回
void
已被弃用
use same API in FWorkSheet. Customize the row header of the spreadsheet.
示例
univerAPI.customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, rowsCfg: ['MokaII', undefined, null, { text: 'Size', textAlign: 'left' }] });
deleteWatermark()
deleteWatermark(): FUniver
Deletes the currently applied watermark from the unit.
This function retrieves the watermark service and invokes the method to remove any existing watermark configuration.
返回
disposeUnit()
disposeUnit(unitId): boolean
Dispose the UniverSheet by the unitId
. The UniverSheet would be unload from the application.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | The unit id of the UniverSheet. |
返回
boolean
Whether the Univer instance is disposed successfully.
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const unitId = fWorkbook?.getId();
if (unitId) {
univerAPI.disposeUnit(unitId);
}
executeCommand()
executeCommand<P, R>(
id,
params?,
options?): Promise<R>
Execute a command with the given id and parameters.
类型参数
类型参数 | 默认类型 |
---|---|
P extends object | object |
R | boolean |
参数
参数 | 类型 | 描述 |
---|---|---|
id | string | Identifier of the command. |
params ? | P | Parameters of this execution. |
options ? | IExecutionOptions | Options of this execution. |
返回
Promise
<R
>
The result of the execution. It is a boolean value by default which indicates the command is executed.
示例
univerAPI.executeCommand('sheet.command.set-range-values', {
value: { v: "Hello, Univer!" },
range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 }
});
exportXLSXBySnapshot()
exportXLSXBySnapshot(snapshot): Promise<File>
Export XLSX file by workbook data
参数
参数 | 类型 | 描述 |
---|---|---|
snapshot | IWorkbookData | Workbook data |
返回
Promise
<File
>
XLSX file
已被弃用
Please use exportXLSXBySnapshotAsync
instead.
exportXLSXBySnapshotAsync()
exportXLSXBySnapshotAsync(snapshot): Promise<File>
Export XLSX file by workbook data
参数
参数 | 类型 | 描述 |
---|---|---|
snapshot | IWorkbookData | Workbook data |
返回
Promise
<File
>
XLSX file
示例
const file = await univerAPI.exportXLSXBySnapshotAsync(snapshot);
exportXLSXByUnitId()
exportXLSXByUnitId(unitId): Promise<File>
Export XLSX file by unit id
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | Unit id |
返回
Promise
<File
>
XLSX file
已被弃用
Please use exportXLSXByUnitIdAsync
instead.
exportXLSXByUnitIdAsync()
exportXLSXByUnitIdAsync(unitId): Promise<File>
Export XLSX file by unit id
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | Unit id |
返回
Promise
<File
>
XLSX file
示例
const file = await univerAPI.exportXLSXByUnitIdAsync(unitId);
generatePivotTable()
generatePivotTable<T>(data, CustomDataFieldManager?): FGenericPivotTable
Create a pivot table instance that does not depend on a workbook
类型参数
类型参数 |
---|
T extends DataFieldManager |
参数
参数 | 类型 | 描述 |
---|---|---|
data | […[], ...(...)[][] ] | The data used to create the pivot table |
CustomDataFieldManager ? | (…args ) => T | The custom data field manager class. If not passed, the default DataFieldManager will be used |
返回
The generated pivot table instance.
示例
const sourceData = [
["区域", "省份", "城市", "类别", "商品", "数量", "销售日期"],
["西部", "河南", "洛阳", "fruit", "葡萄", 38, "2021-06-30"],
["北部", "辽宁", "沈阳", "fruit", "葡萄", 45, "2023-08-31"]
]
const pivot = univerAPI.generatePivotTable(sourceData);
pivot.addFieldWithName('数量', 3);
const res = pivot.getResultByCalculate();
console.log('debugger', pivot, res);
getActiveDocument()
getActiveDocument(): FDocument
Get the currently focused Univer document.
返回
The currently focused Univer document.
getActiveSheet()
getActiveSheet(): Nullable<{
workbook: ...;
worksheet: ...;
}>
Get the active sheet.
返回
Nullable
<{
workbook
: …;
worksheet
: …;
}>
The active sheet.
示例
const target = univerAPI.getActiveSheet();
if (!target) return;
const { workbook, worksheet } = target;
console.log(workbook, worksheet);
getActiveUniverSheet()
getActiveUniverSheet(): FWorkbook
返回
已被弃用
use univerAPI.getActiveWorkbook
instead
getActiveWorkbook()
getActiveWorkbook(): FWorkbook
Get the currently focused Univer spreadsheet.
返回
The currently focused Univer spreadsheet.
示例
const fWorkbook = univerAPI.getActiveWorkbook();
console.log(fWorkbook);
getCollaboration()
getCollaboration(): FCollaboration
Get the collaboration instance to manage the collaboration issue of the current univer.
返回
The collaboration instance.
示例
const collaboration = univerAPI.getCollaboration();
getCommandSheetTarget()
getCommandSheetTarget(commandInfo): Nullable<{
workbook: ...;
worksheet: ...;
}>
Get the target of the sheet.
参数
参数 | 类型 | 描述 |
---|---|---|
commandInfo | ICommandInfo <object > | The commandInfo of the command. |
返回
Nullable
<{
workbook
: …;
worksheet
: …;
}>
- The target of the sheet.
示例
univerAPI.addEvent(univerAPI.Event.CommandExecuted, (commandInfo) => {
const target = univerAPI.getCommandSheetTarget(commandInfo);
if (!target) return;
const { workbook, worksheet } = target;
console.log(workbook, worksheet);
});
getComponentManager()
getComponentManager(): ComponentManager
Get the component manager
返回
ComponentManager
The component manager
getCrosshairHighlightColor()
getCrosshairHighlightColor(): string
Get the color of the crosshair highlight.
返回
string
The color of the crosshair highlight
示例
console.log(univerAPI.getCrosshairHighlightColor());
getCrosshairHighlightEnabled()
getCrosshairHighlightEnabled(): boolean
Get whether the crosshair highlight is enabled.
返回
boolean
Whether the crosshair highlight is enabled
示例
console.log(univerAPI.getCrosshairHighlightEnabled());
getCurrentLifecycleStage()
getCurrentLifecycleStage(): LifecycleStages
Get the current lifecycle stage.
返回
LifecycleStages
- The current lifecycle stage.
示例
const stage = univerAPI.getCurrentLifecycleStage();
console.log(stage);
getFormula()
getFormula(): FFormula
返回
getHooks()
getHooks(): FHooks
Get hooks.
返回
FHooks instance
已被弃用
use addEvent
instead.
getPermission()
getPermission(): FPermission
Get the PermissionInstance.
返回
已被弃用
This function is deprecated and will be removed in version 0.6.0. Please use the function with the same name on the FWorkbook
instance instead.
getSheetHooks()
getSheetHooks(): FSheetHooks
返回
已被弃用
use univerAPI.addEvent
as instead.
getSheetTarget()
getSheetTarget(unitId, subUnitId): Nullable<{
workbook: ...;
worksheet: ...;
}>
Get the target of the sheet.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | The unitId of the sheet. |
subUnitId | string | The subUnitId of the sheet. |
返回
Nullable
<{
workbook
: …;
worksheet
: …;
}>
- The target of the sheet.
示例
const unitId = 'workbook-01';
const subUnitId = 'sheet-0001';
const target = univerAPI.getSheetTarget(unitId, subUnitId);
if (!target) return;
const { workbook, worksheet } = target;
console.log(workbook, worksheet);
getShortcut()
getShortcut(): FShortcut
Get the Shortcut handler to interact with Univer’s shortcut functionalities.
返回
getUniverDoc()
getUniverDoc(id): FDocument
Get the document API handler by the document id.
参数
参数 | 类型 | 描述 |
---|---|---|
id | string | The document id. |
返回
The document API instance.
getUniverSheet()
getUniverSheet(id): FWorkbook
Get the spreadsheet API handler by the spreadsheet id.
参数
参数 | 类型 | 描述 |
---|---|---|
id | string | The spreadsheet id. |
返回
The spreadsheet API instance.
示例
const fWorkbook = univerAPI.getUniverSheet('Sheet1');
console.log(fWorkbook);
const fWorkbook = univerAPI.getWorkbook('Sheet1');
console.log(fWorkbook);
getURL()
getURL(): URL
Return the URL of the current page.
返回
URL
the URL object
getUserManager()
getUserManager(): FUserManager
返回
getWorkbook()
getWorkbook(id): FWorkbook
参数
参数 | 类型 |
---|---|
id | string |
返回
importDOCXToSnapshot()
importDOCXToSnapshot(file): Promise<IDocumentData>
Import DOCX file to document data
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<IDocumentData
>
Document data
已被弃用
Please use importDOCXToSnapshotAsync
instead.
importDOCXToSnapshotAsync()
importDOCXToSnapshotAsync(file): Promise<IDocumentData>
Import DOCX file to document data
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<IDocumentData
>
Document data
示例
const snapshot = await univerAPI.importDOCXToSnapshotAsync(file);
importDOCXToUnitId()
importDOCXToUnitId(file): Promise<string>
Import DOCX file to unit id
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<string
>
Unit id
已被弃用
Please use importDOCXToUnitIdAsync
instead.
importDOCXToUnitIdAsync()
importDOCXToUnitIdAsync(file): Promise<string>
Import DOCX file to unit id
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<string
>
Unit id
示例
const unitId = await univerAPI.importDOCXToUnitIdAsync(file);
importXLSXToSnapshot()
importXLSXToSnapshot(file): Promise<IWorkbookData>
Import XLSX file to workbook data
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<IWorkbookData
>
Workbook data
已被弃用
Please use importXLSXToSnapshotAsync
instead.
importXLSXToSnapshotAsync()
importXLSXToSnapshotAsync(file): Promise<IWorkbookData>
Import XLSX file to workbook data
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<IWorkbookData
>
Workbook data
示例
const snapshot = await univerAPI.importXLSXToSnapshotAsync(file);
importXLSXToUnitId()
importXLSXToUnitId(file): Promise<string>
Import XLSX file to unit id
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<string
>
Unit id
已被弃用
Please use importXLSXToUnitIdAsync
instead.
importXLSXToUnitIdAsync()
importXLSXToUnitIdAsync(file): Promise<string>
Import XLSX file to unit id
参数
参数 | 类型 | 描述 |
---|---|---|
file | string | File | File path or file object |
返回
Promise
<string
>
Unit id
示例
const unitId = await univerAPI.importXLSXToUnitIdAsync(file);
isUIVisible()
isUIVisible(key): boolean
Get the visibility of a built-in UI part.
参数
参数 | 类型 | 描述 |
---|---|---|
key | BuiltInUIPart | the built-in UI part |
返回
boolean
the visibility example
univerAPI.isUIVisible(BuiltInUIPart.HEADER);
newBlob()
newBlob(): FBlob
Create a new blob.
返回
The new blob instance
示例
const blob = univerAPI.newBlob();
newColor()
newColor(): ColorBuilder
Create a new color.
返回
ColorBuilder
The new color instance
示例
const color = univerAPI.newColor();
newDataValidation()
newDataValidation(): FDataValidationBuilder
Creates a new instance of FDataValidationBuilder
返回
A new instance of the FDataValidationBuilder class
示例
const rule = FUnvier.newDataValidation();
cell.setDataValidation(rule.requireValueInRange(range));
newDefinedName()
newDefinedName(): FDefinedNameBuilder
Create a new defined name builder.
返回
- The defined name builder.
示例
const fWorkbook = univerAPI.getActiveWorkbook();
const definedNameBuilder = univerAPI.newDefinedName()
.setRef('Sheet1!$A$1')
.setName('MyDefinedName')
.setComment('This is a comment');
console.log(definedNameBuilder);
fWorkbook.insertDefinedNameBuilder(definedNameBuilder.build());
newParagraphStyle()
newParagraphStyle(style?): ParagraphStyleBuilder
Create a new paragraph style.
参数
参数 | 类型 | 描述 |
---|---|---|
style ? | IParagraphStyle | The paragraph style |
返回
ParagraphStyleBuilder
The new paragraph style instance
示例
const richText = univerAPI.newRichText({ body: { dataStream: 'Hello World\r\n' } });
const paragraphStyle = univerAPI.newParagraphStyle({ textStyle: { ff: 'Arial', fs: 12, it: univerAPI.Enum.BooleanNumber.TRUE, bl: univerAPI.Enum.BooleanNumber.TRUE } });
richText.insertParagraph(paragraphStyle);
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1');
range.setRichTextValueForCell(richText);
newParagraphStyleValue()
newParagraphStyleValue(style?): ParagraphStyleValue
Create a new paragraph style value.
参数
参数 | 类型 | 描述 |
---|---|---|
style ? | IParagraphStyle | The paragraph style |
返回
ParagraphStyleValue
The new paragraph style value instance
示例
const paragraphStyleValue = univerAPI.newParagraphStyleValue();
newRichText()
newRichText(data?): RichTextBuilder
Create a new rich text.
参数
参数 | 类型 | 描述 |
---|---|---|
data ? | IDocumentData |
返回
RichTextBuilder
The new rich text instance
示例
const richText = univerAPI.newRichText({ body: { dataStream: 'Hello World\r\n' } });
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1');
range.setRichTextValueForCell(richText);
newRichTextValue()
newRichTextValue(data): RichTextValue
Create a new rich text value.
参数
参数 | 类型 | 描述 |
---|---|---|
data | IDocumentData | The rich text data |
返回
RichTextValue
The new rich text value instance
示例
const richTextValue = univerAPI.newRichTextValue({ body: { dataStream: 'Hello World\r\n' } });
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1');
range.setRichTextValueForCell(richTextValue);
newTextDecoration()
newTextDecoration(decoration?): TextDecorationBuilder
Create a new text decoration.
参数
参数 | 类型 | 描述 |
---|---|---|
decoration ? | ITextDecoration | The text decoration |
返回
TextDecorationBuilder
The new text decoration instance
示例
const decoration = univerAPI.newTextDecoration();
newTextStyle()
newTextStyle(style?): TextStyleBuilder
Create a new text style.
参数
参数 | 类型 | 描述 |
---|---|---|
style ? | ITextStyle | The text style |
返回
TextStyleBuilder
The new text style instance
示例
const textStyle = univerAPI.newTextStyle();
newTextStyleValue()
newTextStyleValue(style?): TextStyleValue
Create a new text style value.
参数
参数 | 类型 | 描述 |
---|---|---|
style ? | ITextStyle | The text style |
返回
TextStyleValue
The new text style value instance
示例
const textStyleValue = univerAPI.newTextStyleValue();
newTheadComment()
newTheadComment(): FTheadCommentBuilder
create a new thread comment
返回
thead comment builder
示例
const comment = univerAPI.newTheadComment().setContent(univerAPI.newRichText().insertText('hello zhangsan'));
onBeforeCommandExecute()
onBeforeCommandExecute(callback): IDisposable
Register a callback that will be triggered before invoking a command.
参数
参数 | 类型 | 描述 |
---|---|---|
callback | CommandListener | The callback. |
返回
IDisposable
The disposable instance.
已被弃用
use univerAPI.addEvent(univerAPI.Event.BeforeCommandExecute, (event) => {})
instead.
onCommandExecuted()
onCommandExecuted(callback): IDisposable
Register a callback that will be triggered when a command is invoked.
参数
参数 | 类型 | 描述 |
---|---|---|
callback | CommandListener | The callback. |
返回
IDisposable
The disposable instance.
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommandExecuted, (event) => {})
instead.
onCommentAdded()
onCommentAdded(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (event ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommentAdded, () => {})
as instead
onCommentDeleted()
onCommentDeleted(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (event ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommentDeleted, () => {})
as instead
onCommentResolved()
onCommentResolved(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (event ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommentResolved, () => {})
as instead
onCommentUpdated()
onCommentUpdated(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (event ) => void |
返回
IDisposable
已被弃用
use univerAPI.addEvent(univerAPI.Event.CommentUpdated, () => {})
as instead
onUniverSheetCreated()
onUniverSheetCreated(callback): IDisposable
参数
参数 | 类型 |
---|---|
callback | (workbook ) => void |
返回
IDisposable
已被弃用
Use univerAPI.addEvent(univerAPI.Event.UnitCreated, () => {})
openDialog()
openDialog(dialog): IDisposable
Open a dialog.
参数
参数 | 类型 | 描述 |
---|---|---|
dialog | IDialogPartMethodOptions | the dialog options |
返回
IDisposable
the disposable object
openSidebar()
openSidebar(params): IDisposable
Open a sidebar.
参数
参数 | 类型 | 描述 |
---|---|---|
params | ISidebarMethodOptions | the sidebar options |
返回
IDisposable
the disposable object
已被弃用
Please use openSidebar
instead.
openSiderbar()
openSiderbar(params): IDisposable
Open a sidebar.
参数
参数 | 类型 | 描述 |
---|---|---|
params | ISidebarMethodOptions | the sidebar options |
返回
IDisposable
the disposable object
已被弃用
Please use openSidebar
instead.
paste()
paste(): Promise<boolean>
Paste into the current selected position of the currently focused unit from your system clipboard.
返回
Promise
<boolean
>
redo()
redo(): Promise<boolean>
Redo an editing on the currently focused document.
返回
Promise
<boolean
>
redo result
示例
univerAPI.redo();
registerComponent()
registerComponent(
name,
component,
options?): IDisposable
register an component.
参数
参数 | 类型 | 描述 |
---|---|---|
name | string | - |
component | ComponentType | |
options ? | IComponentOptions | - |
返回
IDisposable
示例
univerAPI.registerComponent('my-comp', () => React.createElement('h1', null, 'Custom Header'));
registerFunction()
registerFunction(config): IDisposable
Register a function to the spreadsheet.
参数
参数 | 类型 | 描述 |
---|---|---|
config | IRegisterFunctionParams | The configuration of the function. |
返回
IDisposable
The disposable instance.
已被弃用
Use univerAPI.getFormula().registerFunction
instead.
registerSheetColumnHeaderExtension()
registerSheetColumnHeaderExtension(unitId, ...extensions): IDisposable
Register sheet column header render extensions.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | The unit id of the spreadsheet. |
…extensions | SheetExtension [] | The extensions to register. |
返回
IDisposable
The disposable instance.
registerSheetMainExtension()
registerSheetMainExtension(unitId, ...extensions): IDisposable
Register sheet main render extensions.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | The unit id of the spreadsheet. |
…extensions | SheetExtension [] | The extensions to register. |
返回
IDisposable
The disposable instance.
registerSheetRowHeaderExtension()
registerSheetRowHeaderExtension(unitId, ...extensions): IDisposable
Register sheet row header render extensions.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | The unit id of the spreadsheet. |
…extensions | SheetExtension [] | The extensions to register. |
返回
IDisposable
The disposable instance.
registerUIPart()
registerUIPart(key, component): IDisposable
register an component to a built-in UI part
参数
参数 | 类型 | 描述 |
---|---|---|
key | BuiltInUIPart | the built-in UI part |
component | any | the react component |
返回
IDisposable
示例
univerAPI.registerUIPart(BuiltInUIPart.CUSTOM_HEADER, () => React.createElement('h1', null, 'Custom Header'));
runOnServer()
runOnServer(
scriptNameOrId,
func, ...
params): Promise<string>
Execute a function in a Uniscript on the server.
参数
参数 | 类型 | 描述 |
---|---|---|
scriptNameOrId | string | The name or the ID of the Uniscript to run. Name should end with “.us”. |
func | string | The function in the Uniscript to run |
…params | any [] | Parameters to the function |
返回
Promise
<string
>
setCrosshairHighlightColor()
setCrosshairHighlightColor(color): FUniver
Set the color of the crosshair highlight.
参数
参数 | 类型 | 描述 |
---|---|---|
color | string | The color of the crosshair highlight, if the color not has alpha channel, the alpha channel will be set to 0.5 |
返回
The FUniver instance for chaining
示例
univerAPI.setCrosshairHighlightColor('#FF0000');
// or
univerAPI.setCrosshairHighlightColor('rgba(232, 11, 11, 0.2)');
setCrosshairHighlightEnabled()
setCrosshairHighlightEnabled(enabled): FUniver
Enable or disable crosshair highlight.
参数
参数 | 类型 | 描述 |
---|---|---|
enabled | boolean | Whether to enable the crosshair highlight |
返回
The FUniver instance for chaining
示例
univerAPI.setCrosshairHighlightEnabled(true);
setCurrent()
setCurrent(unitId): void
Set a unit as the current unit and render a unit in the workbench’s main area. If you have multiple units in Univer, you should call this method to render the unit.
参数
参数 | 类型 | 描述 |
---|---|---|
unitId | string | Unit to be rendered. |
返回
void
示例
Let’s assume you have created two units, unit1
and unit2
. Univer is rendering unit1
and you want to
render unit2
.
univerAPI.setCurrent('unit2');
This will render unit2
in the workbench’s main area.
setUIVisible()
setUIVisible(key, visible): FUniver
Set the visibility of a built-in UI part.
参数
参数 | 类型 | 描述 |
---|---|---|
key | BuiltInUIPart | the built-in UI part |
visible | boolean | the visibility |
返回
the FUniver object example
univerAPI.setUIVisible(BuiltInUIPart.HEADER, false);
showMessage()
showMessage(options): void
Show a message.
参数
参数 | 类型 |
---|---|
options | IMessageProps |
返回
void
示例
const message = univerAPI.showMessage({ key: 'my-message', content: 'Warning', duration: 0 });
someAction().then(() => message.dispose());
syncExecuteCommand()
syncExecuteCommand<P, R>(
id,
params?,
options?): R
Execute a command with the given id and parameters synchronously.
类型参数
类型参数 | 默认类型 |
---|---|
P extends object | object |
R | boolean |
参数
参数 | 类型 | 描述 |
---|---|---|
id | string | Identifier of the command. |
params ? | P | Parameters of this execution. |
options ? | IExecutionOptions | Options of this execution. |
返回
R
The result of the execution. It is a boolean value by default which indicates the command is executed.
示例
univerAPI.syncExecuteCommand('sheet.command.set-range-values', {
value: { v: "Hello, Univer!" },
range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 }
});
undo()
undo(): Promise<boolean>
Undo an editing on the currently focused document.
返回
Promise
<boolean
>
undo result
示例
univerAPI.undo();
newAPI()
static newAPI(wrapped): FUniver
Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.
参数
参数 | 类型 | 描述 |
---|---|---|
wrapped | any | The Univer instance or injector instance. |
返回
- The FUniver instance.
Static
示例
const univerAPI = FUniver.newAPI(univer);