FWorkbookPermission
Implementation class for WorkbookPermission Provides workbook-level permission control
This class should not be instantiated directly. Use factory methods on
univerAPIinstead.
Access
Access through:
Setup
Register @univerjs/sheets or a preset that includes it. In plugin mode, import @univerjs/sheets/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/sheets
FWorkbookPermission.addCollaborator
Add a single collaborator.
addCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>Parameters
user— Required. The user information (userID, name, avatar).role— Required. The role to assign.
Returns
A promise that resolves when the collaborator is added.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.addCollaborator( { userID: 'user1', name: 'John Doe', avatar: 'https://...' }, univerAPI.Enum.UnitRole.Editor,)Types: Promise · ICollaboratorUser · UnitRole
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.canEdit
Check if the workbook is editable.
canEdit(): booleanReturns
true if the workbook can be edited, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()if (fWorkbook.getWorkbookPermission().canEdit()) { console.log('Workbook is editable')}Package: @univerjs/sheets · Type definitions
FWorkbookPermission.getPoint
Get the value of a specific permission point.
getPoint(point: WorkbookPermissionPoint): booleanParameters
point— Required. The permission point to query.
Returns
true if allowed, false if denied.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()const canPrint = permission.getPoint(univerAPI.Enum.WorkbookPermissionPoint.Print)console.log(canPrint)Types: WorkbookPermissionPoint
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.getSnapshot
Get a snapshot of all permission points.
getSnapshot(): WorkbookPermissionSnapshotReturns
An object containing all permission point values.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const snapshot = fWorkbook.getWorkbookPermission().getSnapshot()console.log(snapshot)Types: WorkbookPermissionSnapshot
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.listCollaborators
List all collaborators of the workbook.
listCollaborators(): Promise<ICollaborator[]>Returns
Array of collaborators with their roles.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()const collaborators = await permission.listCollaborators()console.log(collaborators)Types: ICollaborator · Promise
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.removeCollaborator
Remove a collaborator from the workbook.
removeCollaborator(userId: string): Promise<void>Parameters
userId— Required. The user ID to remove.
Returns
A promise that resolves when the collaborator is removed.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.removeCollaborator('user1')Types: Promise
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.removeCollaborators
Remove multiple collaborators at once.
removeCollaborators(userIds: string[]): Promise<void>Parameters
userIds— Required. Array of user IDs to remove.
Returns
A promise that resolves when the collaborators are removed.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.removeCollaborators(['user1', 'user2'])Types: Promise
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.setCollaborators
Set multiple collaborators at once (replaces existing collaborators).
setCollaborators(collaborators: Array<{ user: ICollaboratorUser; role: UnitRole; }>): Promise<void>Parameters
collaborators— Required. Array of collaborators with user information and role.
Returns
A promise that resolves when the collaborators are set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.setCollaborators([ { user: { userID: 'user1', name: 'John Doe', avatar: 'https://...' }, role: univerAPI.Enum.UnitRole.Editor, }, { user: { userID: 'user2', name: 'Jane Smith', avatar: '' }, role: univerAPI.Enum.UnitRole.Reader, },])Types: Promise · Array · ICollaboratorUser · UnitRole
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.setEditable
Set the workbook to editable mode (editor mode).
setEditable(): Promise<void>Returns
A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()await fWorkbook.getWorkbookPermission().setEditable()Types: Promise
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.setMode
Set permission mode for the workbook.
setMode(mode: WorkbookMode): Promise<void>Parameters
mode— Required. The permission mode to set ('owner' | 'editor' | 'viewer' | 'commenter').
Returns
A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()await fWorkbook.getWorkbookPermission().setMode('editor')Types: Promise · WorkbookMode
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.setPoint
Set a specific permission point.
setPoint(point: WorkbookPermissionPoint, value: boolean): Promise<void>Parameters
point— Required. The permission point to set.value— Required. The value to set (true = allowed, false = denied).
Returns
A promise that resolves when the point is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.setPoint(univerAPI.Enum.WorkbookPermissionPoint.Print, false)Types: Promise · WorkbookPermissionPoint
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.setReadOnly
Set the workbook to read-only mode (viewer mode).
setReadOnly(): Promise<void>Returns
A promise that resolves when the mode is set.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()await fWorkbook.getWorkbookPermission().setReadOnly()Types: Promise
Package: @univerjs/sheets · Type definitions
FWorkbookPermission.updateCollaborator
Update an existing collaborator's role and information.
updateCollaborator(user: ICollaboratorUser, role: UnitRole): Promise<void>Parameters
user— Required. The updated user information (userID, name, avatar).role— Required. The new role to assign.
Returns
A promise that resolves when the collaborator is updated.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const permission = fWorkbook.getWorkbookPermission()await permission.updateCollaborator( { userID: 'user1', name: 'John Doe Updated', avatar: 'https://...' }, univerAPI.Enum.UnitRole.Reader,)Types: Promise · ICollaboratorUser · UnitRole
Package: @univerjs/sheets · Type definitions
How is this guide?