FUniver
| packages | @univerjs/core |
|---|
The root Facade API object to interact with Univer. Please use newAPI static method
to create a new instance.
APIs
addEvent
Add an event listener
Signature
addEvent<T extends keyof IEventParamConfig>(event: T, callback: (params: IEventParamConfig[T]) => void): IDisposableParameters
event(T) — key of eventcallback((params: IEventParamConfig[T]) => void) — callback when event triggered
Returns
- (
IDisposable) — The Disposable instance, for remove the listener
Examples
// 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()`disposeUnit
Dispose the UniverSheet by the unitId. The UniverSheet would be unload from the application.
Signature
disposeUnit(unitId: string): booleanParameters
unitId(string) — The unit id of the UniverSheet.
Returns
- (
boolean) — Whether the Univer instance is disposed successfully.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const unitId = fWorkbook?.getId()
if (unitId) {
univerAPI.disposeUnit(unitId)
}Enum
Signature
get Enum(): FEnumEvent
Signature
get Event(): FEventNameexecuteCommand
Execute a command with the given id and parameters.
Signature
executeCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): Promise<R>Parameters
id(string) — Identifier of the command.params(P) — Parameters of this execution.options(IExecutionOptions) — Options of this execution.
Returns
- (
Promise<R>) — The result of the execution. It is a boolean value by default which indicates the command is executed.
Examples
univerAPI.executeCommand('sheet.command.set-range-values', {
value: { v: 'Hello, Univer!' },
range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 },
})fireEvent
Fire an event, used in internal only.
Signature
fireEvent<T extends keyof IEventParamConfig>(event: T, params: IEventParamConfig[T]): boolean | undefinedParameters
event(T) — key of eventparams(IEventParamConfig[T]) — params of event
Returns
- (
boolean | undefined) — should cancel
Examples
this.fireEvent(univerAPI.Event.LifeCycleChanged, params)getCurrentLifecycleStage
Get the current lifecycle stage.
Signature
getCurrentLifecycleStage(): LifecycleStagesReturns
- (
LifecycleStages) — - The current lifecycle stage.
Examples
const stage = univerAPI.getCurrentLifecycleStage()
console.log(stage)getHooks
Get hooks.
Deprecated
use addEvent instead.
Signature
getHooks(): FHooksReturns
- (
FHooks) — FHooks instance
getUserManager
Signature
getUserManager(): FUserManagerloadLocales
Load locales for the given locale.
Signature
loadLocales(locale: string, locales: ILanguagePack): voidParameters
locale(string) — - A unique locale identifier.locales(ILanguagePack) — - The locales object containing the translations.
Tags
@description— This method is utilized to load locales, which can be either built-in or custom-defined.
Examples
univerAPI.loadLocales('esES', {
'Hello World': 'Hola Mundo',
})newAPI
Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.
Signature
static newAPI(wrapped: Univer | Injector): FUniverParameters
wrapped(Univer | Injector) — - The Univer instance or injector instance.
Returns
- (
FUniver) — - The FUniver instance.
Tags
@static
Examples
const univerAPI = FUniver.newAPI(univer)newBlob
Create a new blob.
Signature
newBlob(): FBlobReturns
- (
FBlob) — The new blob instance
Examples
const blob = univerAPI.newBlob()newColor
Create a new color.
Deprecated Deprecated.
Signature
newColor(): ColorBuilderReturns
- (
ColorBuilder) — The new color instance
Examples
const color = univerAPI.newColor()newParagraphStyle
Create a new paragraph style.
Signature
newParagraphStyle(style?: IParagraphStyle): ParagraphStyleBuilderParameters
style(IParagraphStyle) — - The paragraph style
Returns
- (
ParagraphStyleBuilder) — The new paragraph style instance
Examples
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
Create a new paragraph style value.
Signature
newParagraphStyleValue(style?: IParagraphStyle): ParagraphStyleValueParameters
style(IParagraphStyle) — - The paragraph style
Returns
- (
ParagraphStyleValue) — The new paragraph style value instance
Examples
const paragraphStyleValue = univerAPI.newParagraphStyleValue()newRichText
Create a new rich text.
Signature
newRichText(data?: IDocumentData): RichTextBuilderParameters
data(IDocumentData)
Returns
- (
RichTextBuilder) — The new rich text instance
Examples
const richText = univerAPI.newRichText({ body: { dataStream: 'Hello World\r\n' } })
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1')
range.setRichTextValueForCell(richText)newRichTextValue
Create a new rich text value.
Signature
newRichTextValue(data: IDocumentData): RichTextValueParameters
data(IDocumentData) — - The rich text data
Returns
- (
RichTextValue) — The new rich text value instance
Examples
const richTextValue = univerAPI.newRichTextValue({ body: { dataStream: 'Hello World\r\n' } })
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1')
range.setRichTextValueForCell(richTextValue)newTextDecoration
Create a new text decoration.
Signature
newTextDecoration(decoration?: ITextDecoration): TextDecorationBuilderParameters
decoration(ITextDecoration) — - The text decoration
Returns
- (
TextDecorationBuilder) — The new text decoration instance
Examples
const decoration = univerAPI.newTextDecoration()newTextStyle
Create a new text style.
Signature
newTextStyle(style?: ITextStyle): TextStyleBuilderParameters
style(ITextStyle) — - The text style
Returns
- (
TextStyleBuilder) — The new text style instance
Examples
const textStyle = univerAPI.newTextStyle()newTextStyleValue
Create a new text style value.
Signature
newTextStyleValue(style?: ITextStyle): TextStyleValueParameters
style(ITextStyle) — - The text style
Returns
- (
TextStyleValue) — The new text style value instance
Examples
const textStyleValue = univerAPI.newTextStyleValue()onBeforeCommandExecute
Register a callback that will be triggered before invoking a command.
Deprecated
use univerAPI.addEvent(univerAPI.Event.BeforeCommandExecute, (event) => \{\}) instead.
Signature
onBeforeCommandExecute(callback: CommandListener): IDisposableParameters
callback(CommandListener) — The callback.
Returns
- (
IDisposable) — The disposable instance.
onCommandExecuted
Register a callback that will be triggered when a command is invoked.
Deprecated
use univerAPI.addEvent(univerAPI.Event.CommandExecuted, (event) => \{\}) instead.
Signature
onCommandExecuted(callback: CommandListener): IDisposableParameters
callback(CommandListener) — The callback.
Returns
- (
IDisposable) — The disposable instance.
redo
Redo an editing on the currently focused document.
Signature
redo(): Promise<boolean>Returns
- (
Promise<boolean>) — redo result
Examples
await univerAPI.redo()setLocale
Set the current locale.
Signature
setLocale(locale: string): voidParameters
locale(string) — - A unique locale identifier.
Examples
univerAPI.setLocale('esES')syncExecuteCommand
Execute a command with the given id and parameters synchronously.
Signature
syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): RParameters
id(string) — Identifier of the command.params(P) — Parameters of this execution.options(IExecutionOptions) — Options of this execution.
Returns
- (
R) — The result of the execution. It is a boolean value by default which indicates the command is executed.
Examples
univerAPI.syncExecuteCommand('sheet.command.set-range-values', {
value: { v: 'Hello, Univer!' },
range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 },
})toggleDarkMode
Toggle dark mode on or off.
Signature
toggleDarkMode(isDarkMode: boolean): voidParameters
isDarkMode(boolean) — - Whether the dark mode is enabled.
Examples
univerAPI.toggleDarkMode(true)undo
Undo an editing on the currently focused document.
Signature
undo(): Promise<boolean>Returns
- (
Promise<boolean>) — undo result
Examples
await univerAPI.undo()Util
Signature
get Util(): FUtil