Skip to Content
ClassesFUniver

Class: FUniver

The root Facade API object to interact with Univer. Please use newAPI static method to create a new instance.

Extends

  • FBaseInitialable.IFUniverSheetsMixin.IFUniverNetworkMixin.IFUniverEngineFormulaMixin.IFUnvierDataValidationMixin.IFUniverSheetsFormulaMixin.IFUniverCollaborationClientMixin.IFUniverSheetsUIMixin.IFUniverUIMixin.IFUniverDocsUIMixin.IFUniverFindReplaceMixin.IFUniverCrosshairHighlightMixin.IFUniverWatermarkMixin.IFUniverSheetsZenEditorMixin.IFUniverNodeRuntimeMixin.IFUniverExchangeClientMixin

Properties

PropertyModifierTypeDescription

CROSSHAIR_HIGHLIGHT_COLORS

readonly

string[]

Get the available built-in colors for the crosshair highlight.

Accessors

Enum

Get Signature

get Enum(): FEnum
Returns

FEnum


Event

Get Signature

get Event(): FEventName
Returns

FEventName


Util

Get Signature

get Util(): FUtil
Returns

FUtil

Methods

addEvent()

addEvent<T>(event, callback): IDisposable

Add an event listener

Type Parameters

Type Parameter
T extends keyof IEventParamConfig

Parameters

ParameterTypeDescription
eventTkey of event
callback(params) => voidcallback when event triggered

Returns

IDisposable

The Disposable instance, for remove the listener

Example

univerAPI.addEvent(univerAPI.event.UnitCreated, (params) => { console.log('unit created', params); });

addWatermark()

Call Signature

addWatermark(type, config): FUniver

Adds a watermark to the unit. Supports both text and image watermarks based on the specified type.

Parameters
ParameterTypeDescription
typeTextThe type of watermark to add. Can be either ‘Text’ or ‘Image’.
configITextWatermarkConfigThe 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.
Returns

FUniver

Throws

Throws an error if the watermark type is unknown.

Call Signature

addWatermark(type, config): FUniver
Parameters
ParameterType
typeImage
configIImageWatermarkConfig
Returns

FUniver

Call Signature

addWatermark(type, config): FUniver
Parameters
ParameterType
typeany
configany
Returns

FUniver


copy()

copy(): Promise<boolean>

Copy the current selected content of the currently focused unit into your system clipboard.

Returns

Promise<boolean>


createMenu()

createMenu(menuItem): FMenu

Create a menu build object. You can insert new menus into the UI.

Parameters

ParameterTypeDescription
menuItemIFacadeMenuItemthe menu item

Returns

FMenu

the FMenu object

Example

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.

Parameters

ParameterTypeDescription
submenuItemIFacadeSubmenuItemthe submenu item

Returns

FSubmenu

the FSubmenu object

Example

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.

Parameters

ParameterTypeDescription
textstringThe text to find.

Returns

Promise<FTextFinder>

A promise that resolves to the text-finder instance.

Example

const textFinder = await univerAPI.createTextFinderAsync('Hello');

createUniverDoc()

createUniverDoc(data): FDocument

Create a new document and get the API handler of that document.

Parameters

ParameterTypeDescription
dataPartial<IDocumentData>The snapshot of the document.

Returns

FDocument

FDocument API instance.


createUniverSheet()

createUniverSheet(data): FWorkbook

Parameters

ParameterType
dataPartial<IWorkbookData>

Returns

FWorkbook

Deprecated

use univerAPI.createWorkbook instead.


createWorkbook()

createWorkbook(data): FWorkbook

Create a new spreadsheet and get the API handler of that spreadsheet.

Parameters

ParameterTypeDescription
dataPartial<IWorkbookData>The snapshot of the spreadsheet.

Returns

FWorkbook

FWorkbook API instance.

Example

univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' });

customizeColumnHeader()

customizeColumnHeader(cfg): void

Parameters

ParameterTypeDescription
cfgIColumnsHeaderCfgParamThe configuration of the column header.

Returns

void

Deprecated

use same API in FWorkSheet. Customize the column header of the spreadsheet.

Example

univerAPI.customizeColumnHeader({ headerStyle: { fontColor: '#fff', size: 40, backgroundColor: '#4e69ee', fontSize: 9 }, columnsCfg: ['MokaII', undefined, null, { text: 'Size', textAlign: 'left' }] });

customizeRowHeader()

customizeRowHeader(cfg): void

Parameters

ParameterTypeDescription
cfgIRowsHeaderCfgParamThe configuration of the row header.

Returns

void

Deprecated

use same API in FWorkSheet. Customize the row header of the spreadsheet.

Example

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.

Returns

FUniver


disposeUnit()

disposeUnit(unitId): boolean

Dispose the UniverSheet by the unitId. The UniverSheet would be unload from the application.

Parameters

ParameterTypeDescription
unitIdstringThe unit id of the UniverSheet.

Returns

boolean

Whether the Univer instance is disposed successfully.


executeCommand()

executeCommand<P, R>( id, params?, options?): Promise<R>

Execute a command with the given id and parameters.

Type Parameters

Type ParameterDefault type
P extends objectobject
Rboolean

Parameters

ParameterTypeDescription
idstringIdentifier of the command.
params?PParameters of this execution.
options?IExecutionOptionsOptions of this execution.

Returns

Promise<R>

The result of the execution. It is a boolean value by default which indicates the command is executed.


exportXLSXBySnapshot()

exportXLSXBySnapshot(snapshot): Promise<File>

Export XLSX file by workbook data

Parameters

ParameterTypeDescription
snapshotIWorkbookDataWorkbook data

Returns

Promise<File>

XLSX file

Deprecated

Please use exportXLSXBySnapshotAsync instead.


exportXLSXBySnapshotAsync()

exportXLSXBySnapshotAsync(snapshot): Promise<File>

Export XLSX file by workbook data

Parameters

ParameterTypeDescription
snapshotIWorkbookDataWorkbook data

Returns

Promise<File>

XLSX file

Example

const file = await univerAPI.exportXLSXBySnapshotAsync(snapshot);

exportXLSXByUnitId()

exportXLSXByUnitId(unitId): Promise<File>

Export XLSX file by unit id

Parameters

ParameterTypeDescription
unitIdstringUnit id

Returns

Promise<File>

XLSX file

Deprecated

Please use exportXLSXByUnitIdAsync instead.


exportXLSXByUnitIdAsync()

exportXLSXByUnitIdAsync(unitId): Promise<File>

Export XLSX file by unit id

Parameters

ParameterTypeDescription
unitIdstringUnit id

Returns

Promise<File>

XLSX file

Example

const file = await univerAPI.exportXLSXByUnitIdAsync(unitId);

getActiveDocument()

getActiveDocument(): FDocument

Get the currently focused Univer document.

Returns

FDocument

The currently focused Univer document.


getActiveSheet()

getActiveSheet(): Nullable<{ workbook: ...; worksheet: ...; }>

Get the active sheet.

Returns

Nullable<{ workbook: …; worksheet: …; }>

The active sheet.

Example

const target = univerAPI.getActiveSheet(); if (!target) return; const { workbook, worksheet } = target;

getActiveUniverSheet()

getActiveUniverSheet(): FWorkbook

Returns

FWorkbook

Deprecated

use univerAPI.getActiveWorkbook instead


getActiveWorkbook()

getActiveWorkbook(): FWorkbook

Get the currently focused Univer spreadsheet.

Returns

FWorkbook

The currently focused Univer spreadsheet.

Example

univerAPI.getActiveWorkbook();

getCollaboration()

getCollaboration(): FCollaboration

Get the collaboration instance to manage the collaboration issue of the current univer.

Returns

FCollaboration

The collaboration instance.

Example

const collaboration = univerAPI.getCollaboration();

getCommandSheetTarget()

getCommandSheetTarget(commandInfo): Nullable<{ workbook: ...; worksheet: ...; }>

Get the target of the sheet.

Parameters

ParameterTypeDescription
commandInfoICommandInfo<object>The commandInfo of the command.

Returns

Nullable<{ workbook: …; worksheet: …; }>

  • The target of the sheet.

Example

univerAPI.addEvent(univerAPI.event.CommandExecuted, (commandInfo) => { const target = univerAPI.getCommandSheetTarget(commandInfo); if (!target) return; const { workbook, worksheet } = target; });

getComponentManager()

getComponentManager(): ComponentManager

Get the component manager

Returns

ComponentManager

The component manager


getCrosshairHighlightColor()

getCrosshairHighlightColor(): string

Get the color of the crosshair highlight.

Returns

string

the color of the crosshair highlight

Example

const color = univer.getCrosshairHighlightColor();

getCrosshairHighlightEnabled()

getCrosshairHighlightEnabled(): boolean

Get whether the crosshair highlight is enabled.

Returns

boolean

whether the crosshair highlight is enabled

Example

const enabled = univer.getCrosshairHighlightEnabled();

getCurrentLifecycleStage()

getCurrentLifecycleStage(): LifecycleStages

Get the current lifecycle stage.

Returns

LifecycleStages

  • The current lifecycle stage.

getFormula()

getFormula(): FFormula

Returns

FFormula


getHooks()

getHooks(): FHooks

Get hooks.

Returns

FHooks

FHooks instance

Deprecated

use addEvent instead.


getNetwork()

getNetwork(): FNetwork

Get the network API of Univer, with the help of which you can send HTTP requests.

Returns

FNetwork


getPermission()

getPermission(): FPermission

Get the PermissionInstance.

Returns

FPermission

Deprecated

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

Returns

FSheetHooks

Deprecated

use univerAPI.addEvent as instead.


getSheetTarget()

getSheetTarget(unitId, subUnitId): Nullable<{ workbook: ...; worksheet: ...; }>

Get the target of the sheet.

Parameters

ParameterTypeDescription
unitIdstringThe unitId of the sheet.
subUnitIdstringThe subUnitId of the sheet.

Returns

Nullable<{ workbook: …; worksheet: …; }>

  • The target of the sheet.

Example

univerAPI.getSheetTarget('unitId', 'subUnitId');

getShortcut()

getShortcut(): FShortcut

Get the Shortcut handler to interact with Univer’s shortcut functionalities.

Returns

FShortcut


getUniverDoc()

getUniverDoc(id): FDocument

Get the document API handler by the document id.

Parameters

ParameterTypeDescription
idstringThe document id.

Returns

FDocument

The document API instance.


getUniverSheet()

getUniverSheet(id): FWorkbook

Get the spreadsheet API handler by the spreadsheet id.

Parameters

ParameterTypeDescription
idstringThe spreadsheet id.

Returns

FWorkbook

The spreadsheet API instance.


getURL()

getURL(): URL

Return the URL of the current page.

Returns

URL

the URL object


getUserManager()

getUserManager(): FUserManager

Returns

FUserManager


getWorkbook()

getWorkbook(id): FWorkbook

Parameters

ParameterType
idstring

Returns

FWorkbook


importDOCXToSnapshot()

importDOCXToSnapshot(file): Promise<IDocumentData>

Import DOCX file to document data

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<IDocumentData>

Document data

Deprecated

Please use importDOCXToSnapshotAsync instead.


importDOCXToSnapshotAsync()

importDOCXToSnapshotAsync(file): Promise<IDocumentData>

Import DOCX file to document data

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<IDocumentData>

Document data

Example

const snapshot = await univerAPI.importDOCXToSnapshotAsync(file);

importDOCXToUnitId()

importDOCXToUnitId(file): Promise<string>

Import DOCX file to unit id

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<string>

Unit id

Deprecated

Please use importDOCXToUnitIdAsync instead.


importDOCXToUnitIdAsync()

importDOCXToUnitIdAsync(file): Promise<string>

Import DOCX file to unit id

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<string>

Unit id

Example

const unitId = await univerAPI.importDOCXToUnitIdAsync(file);

importXLSXToSnapshot()

importXLSXToSnapshot(file): Promise<IWorkbookData>

Import XLSX file to workbook data

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<IWorkbookData>

Workbook data

Deprecated

Please use importXLSXToSnapshotAsync instead.


importXLSXToSnapshotAsync()

importXLSXToSnapshotAsync(file): Promise<IWorkbookData>

Import XLSX file to workbook data

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<IWorkbookData>

Workbook data

Example

const snapshot = await univerAPI.importXLSXToSnapshotAsync(file);

importXLSXToUnitId()

importXLSXToUnitId(file): Promise<string>

Import XLSX file to unit id

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<string>

Unit id

Deprecated

Please use importXLSXToUnitIdAsync instead.


importXLSXToUnitIdAsync()

importXLSXToUnitIdAsync(file): Promise<string>

Import XLSX file to unit id

Parameters

ParameterTypeDescription
filestring | FileFile path or file object

Returns

Promise<string>

Unit id

Example

const unitId = await univerAPI.importXLSXToUnitIdAsync(file);

isUIVisible()

isUIVisible(key): boolean

Get the visibility of a built-in UI part.

Parameters

ParameterTypeDescription
keyBuiltInUIPartthe built-in UI part

Returns

boolean

the visibility example

univerAPI.isUIVisible(BuiltInUIPart.HEADER);

newBlob()

newBlob(): FBlob

Create a new blob.

Returns

FBlob

The new blob instance

Example

const blob = univerAPI.newBlob();

newColor()

newColor(): ColorBuilder

Create a new color.

Returns

ColorBuilder

The new color instance

Example

const color = univerAPI.newColor();

newDataValidation()

newDataValidation(): FDataValidationBuilder

Creates a new instance of FDataValidationBuilder

Returns

FDataValidationBuilder

A new instance of the FDataValidationBuilder class

Example

const rule = FUnvier.newDataValidation(); cell.setDataValidation(rule.requireValueInRange(range));

newDefinedName()

newDefinedName(): FDefinedNameBuilder

Create a new defined name builder.

Returns

FDefinedNameBuilder

  • The defined name builder.

Example

univerAPI.newDefinedName();

newParagraphStyle()

newParagraphStyle(style?): ParagraphStyleBuilder

Create a new paragraph style.

Parameters

ParameterTypeDescription
style?IParagraphStyleThe paragraph style

Returns

ParagraphStyleBuilder

The new paragraph style instance

Example

const paragraphStyle = univerAPI.newParagraphStyle();

newParagraphStyleValue()

newParagraphStyleValue(style?): ParagraphStyleValue

Create a new paragraph style value.

Parameters

ParameterTypeDescription
style?IParagraphStyleThe paragraph style

Returns

ParagraphStyleValue

The new paragraph style value instance

Example

const paragraphStyleValue = univerAPI.newParagraphStyleValue();

newRichText()

newRichText(data?): RichTextBuilder

Create a new rich text.

Parameters

ParameterTypeDescription
data?IDocumentData

Returns

RichTextBuilder

The new rich text instance

Example

const richText = univerAPI.newRichText();

newRichTextValue()

newRichTextValue(data): RichTextValue

Create a new rich text value.

Parameters

ParameterTypeDescription
dataIDocumentDataThe rich text data

Returns

RichTextValue

The new rich text value instance

Example

const richTextValue = univerAPI.newRichTextValue();

newTextDecoration()

newTextDecoration(decoration?): TextDecorationBuilder

Create a new text decoration.

Parameters

ParameterTypeDescription
decoration?ITextDecorationThe text decoration

Returns

TextDecorationBuilder

The new text decoration instance

Example

const decoration = univerAPI.newTextDecoration();

newTextStyle()

newTextStyle(style?): TextStyleBuilder

Create a new text style.

Parameters

ParameterTypeDescription
style?ITextStyleThe text style

Returns

TextStyleBuilder

The new text style instance

Example

const textStyle = univerAPI.newTextStyle();

newTextStyleValue()

newTextStyleValue(style?): TextStyleValue

Create a new text style value.

Parameters

ParameterTypeDescription
style?ITextStyleThe text style

Returns

TextStyleValue

The new text style value instance

Example

const textStyleValue = univerAPI.newTextStyleValue();

onBeforeCommandExecute()

onBeforeCommandExecute(callback): IDisposable

Register a callback that will be triggered before invoking a command.

Parameters

ParameterTypeDescription
callbackCommandListenerThe callback.

Returns

IDisposable

The disposable instance.

Deprecated

use addEvent(univerAPI.event.BeforeCommandExecute, () => {}) instead.


onCommandExecuted()

onCommandExecuted(callback): IDisposable

Register a callback that will be triggered when a command is invoked.

Parameters

ParameterTypeDescription
callbackCommandListenerThe callback.

Returns

IDisposable

The disposable instance.

Deprecated

use addEvent(univerAPI.event.CommandExecuted, () => {}) instead.


onUniverSheetCreated()

onUniverSheetCreated(callback): IDisposable

Parameters

ParameterType
callback(workbook) => void

Returns

IDisposable

Deprecated

Use univerAPI.addEvent(univerAPI.Event.UnitCreated, () => {})


openDialog()

openDialog(dialog): IDisposable

Open a dialog.

Parameters

ParameterTypeDescription
dialogIDialogPartMethodOptionsthe dialog options

Returns

IDisposable

the disposable object


openSidebar()

openSidebar(params): IDisposable

Open a sidebar.

Parameters

ParameterTypeDescription
paramsISidebarMethodOptionsthe sidebar options

Returns

IDisposable

the disposable object

Deprecated

Please use openSidebar instead.


openSiderbar()

openSiderbar(params): IDisposable

Open a sidebar.

Parameters

ParameterTypeDescription
paramsISidebarMethodOptionsthe sidebar options

Returns

IDisposable

the disposable object

Deprecated

Please use openSidebar instead.


paste()

paste(): Promise<boolean>

Paste into the current selected position of the currently focused unit from your system clipboard.

Returns

Promise<boolean>


redo()

redo(): Promise<boolean>

Redo an editing on the currently focused document.

Returns

Promise<boolean>

redo result


registerComponent()

registerComponent( name, component, options?): IDisposable

register an component.

Parameters

ParameterTypeDescription
namestring-
componentComponentType
options?IComponentOptions-

Returns

IDisposable

Example

univerAPI.registerComponent('my-comp', () => React.createElement('h1', null, 'Custom Header'));

registerFunction()

registerFunction(config): IDisposable

Register a function to the spreadsheet.

Parameters

ParameterTypeDescription
configIRegisterFunctionParamsThe configuration of the function.

Returns

IDisposable

The disposable instance.

Deprecated

Use univerAPI.getFormula().registerFunction instead.


registerSheetColumnHeaderExtension()

registerSheetColumnHeaderExtension(unitId, ...extensions): IDisposable

Register sheet column header render extensions.

Parameters

ParameterTypeDescription
unitIdstringThe unit id of the spreadsheet.
extensionsSheetExtension[]The extensions to register.

Returns

IDisposable

The disposable instance.


registerSheetMainExtension()

registerSheetMainExtension(unitId, ...extensions): IDisposable

Register sheet main render extensions.

Parameters

ParameterTypeDescription
unitIdstringThe unit id of the spreadsheet.
extensionsSheetExtension[]The extensions to register.

Returns

IDisposable

The disposable instance.


registerSheetRowHeaderExtension()

registerSheetRowHeaderExtension(unitId, ...extensions): IDisposable

Register sheet row header render extensions.

Parameters

ParameterTypeDescription
unitIdstringThe unit id of the spreadsheet.
extensionsSheetExtension[]The extensions to register.

Returns

IDisposable

The disposable instance.


registerUIPart()

registerUIPart(key, component): IDisposable

register an component to a built-in UI part

Parameters

ParameterTypeDescription
keyBuiltInUIPartthe built-in UI part
componentanythe react component

Returns

IDisposable

Example

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.

Parameters

ParameterTypeDescription
scriptNameOrIdstringThe name or the ID of the Uniscript to run. Name should end with “.us”.
funcstringThe function in the Uniscript to run
paramsany[]Parameters to the function

Returns

Promise<string>


setCrosshairHighlightColor()

setCrosshairHighlightColor(color): FUniver

Set the color of the crosshair highlight.

Parameters

ParameterTypeDescription
colorstringthe color of the crosshair highlight

Returns

FUniver

the FUniver instance

Example

univer.setCrosshairHighlightColor('#FF0000');

setCrosshairHighlightEnabled()

setCrosshairHighlightEnabled(enabled): FUniver

Enable or disable crosshair highlight.

Parameters

ParameterTypeDescription
enabledbooleanif crosshair highlight should be enabled

Returns

FUniver

the FUniver instance

Example

univer.setCrosshairHighlightEnabled(true);

setUIVisible()

setUIVisible(key, visible): FUniver

Set the visibility of a built-in UI part.

Parameters

ParameterTypeDescription
keyBuiltInUIPartthe built-in UI part
visiblebooleanthe visibility

Returns

FUniver

the FUniver object example

univerAPI.setUIVisible(BuiltInUIPart.HEADER, false);

showMessage()

showMessage(options): void

Show a message.

Parameters

ParameterType
optionsIMessageProps

Returns

void

Example

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.

Type Parameters

Type ParameterDefault type
P extends objectobject
Rboolean

Parameters

ParameterTypeDescription
idstringIdentifier of the command.
params?PParameters of this execution.
options?IExecutionOptionsOptions of this execution.

Returns

R

The result of the execution. It is a boolean value by default which indicates the command is executed.


undo()

undo(): Promise<boolean>

Undo an editing on the currently focused document.

Returns

Promise<boolean>

undo result


newAPI()

static newAPI(wrapped): FUniver

Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.

Parameters

ParameterTypeDescription
wrappedanyThe Univer instance or injector instance.

Returns

FUniver

  • The FUniver instance.

Static