FUniverSheetsMixin
| packages | @univerjs/sheets |
|---|
APIs
createUniverSheet
Deprecated
use univerAPI.createWorkbook instead.
Signature
createUniverSheet(data: Partial<IWorkbookData>, options?: ICreateUnitOptions): FWorkbookcreateWorkbook
Create a new spreadsheet and get the API handler of that spreadsheet.
Signature
createWorkbook(data: Partial<IWorkbookData>, options?: ICreateUnitOptions): FWorkbookParameters
data(Partial<IWorkbookData>) — The snapshot of the spreadsheet.options(ICreateUnitOptions) — The options of creating the spreadsheet.
Returns
- (
FWorkbook) — FWorkbook API instance.
Examples
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)getActiveSheet
Get the active sheet.
Signature
getActiveSheet(): Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>Returns
- (
Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>) — The active sheet.
Examples
const target = univerAPI.getActiveSheet()
if (!target) return
const { workbook, worksheet } = target
console.log(workbook, worksheet)getActiveUniverSheet
Deprecated
use univerAPI.getActiveWorkbook instead
Signature
getActiveUniverSheet(): FWorkbook | nullgetActiveWorkbook
Get the currently focused Univer spreadsheet.
Signature
getActiveWorkbook(): FWorkbook | nullReturns
- (
FWorkbook | null) — The currently focused Univer spreadsheet.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
console.log(fWorkbook)getCommandSheetTarget
Get the target of the sheet.
Signature
getCommandSheetTarget(commandInfo: ICommandInfo<object>): Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>Parameters
commandInfo(ICommandInfo<object>) — - The commandInfo of the command.
Returns
- (
Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>) — - The target of the sheet.
Examples
univerAPI.addEvent(univerAPI.Event.CommandExecuted, (event) => {
const { options, ...commandInfo } = event
const target = univerAPI.getCommandSheetTarget(commandInfo)
if (!target) return
const { workbook, worksheet } = target
console.log(workbook, worksheet)
})getPermission
Get the PermissionInstance.
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.
Signature
getPermission(): FPermissiongetSheetTarget
Get the target of the sheet.
Signature
getSheetTarget(unitId: string, subUnitId: string): Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>Parameters
unitId(string) — - The unitId of the sheet.subUnitId(string) — - The subUnitId of the sheet.
Returns
- (
Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>) — - The target of the sheet.
Examples
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)getUniverSheet
Get the spreadsheet API handler by the spreadsheet id.
Signature
getUniverSheet(id: string): FWorkbook | nullParameters
id(string) — The spreadsheet id.
Returns
- (
FWorkbook | null) — The spreadsheet API instance.
Examples
const fWorkbook = univerAPI.getUniverSheet('Sheet1')
console.log(fWorkbook)
const fWorkbook = univerAPI.getWorkbook('Sheet1')
console.log(fWorkbook)getWorkbook
Signature
getWorkbook(id: string): FWorkbook | nullnewDefinedName
Create a new defined name builder.
Signature
newDefinedName(): FDefinedNameBuilderReturns
- (
FDefinedNameBuilder) — - The defined name builder.
Examples
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())onUniverSheetCreated
Deprecated
Use univerAPI.addEvent(univerAPI.Event.UnitCreated, () => \{\})
Signature
onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposablesetFreezeSync
Set whether to enable synchronize the frozen state to other users in real-time collaboration.
Signature
setFreezeSync(enabled: boolean): voidParameters
enabled(boolean) — - Whether to enable freeze sync. Default is true.
Examples
// Disable freeze sync
univerAPI.setFreezeSync(false)