Permission Control
Use a workbook mode to control editing and commenting across a spreadsheet. To let selected collaborators edit a sheet or a range, protect that sheet or range. In a collaborative deployment, the server must also authorize reads, session joins, and document changes. See Identity and authorization.
Common tasks
Make a workbook read-only or allow comments
The viewer mode allows viewing and printing. Use 'commenter' instead to allow comments while keeping cells read-only. A mode sets several permission points at once. To change one person’s role, use the collaborator APIs.
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const permission = fWorkbook.getWorkbookPermission()await permission.setMode('viewer')To change a single point, call setPoint. For example, await permission.setPoint(univerAPI.Enum.WorkbookPermissionPoint.Edit, false) turns off workbook editing. When the value changes, the SDK calls IAuthzIoService.update with the policy role Editor for true or Owner for false. To keep the policy when the document reopens, connect an authorization service.
Let selected collaborators edit a worksheet
Replace user1 and user2 with IDs of existing workbook collaborators. Create the protection rule with protect() before setting individual worksheet permission points. Call worksheetPermission.unprotect() to remove worksheet protection.
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const fWorksheet = fWorkbook.getActiveSheet()const worksheetPermission = fWorksheet.getWorksheetPermission()await worksheetPermission.protect({ allowedUsers: ['user1', 'user2'], name: 'My Worksheet Protection',})Restrict viewing and editing of A1:B2 to selected collaborators
allowedUsers identifies the collaborators who can edit the range. Set allowViewByOthers: false to also restrict who can see it. Call rule.remove() on the returned rule to remove just that protection.
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const fWorksheet = fWorkbook.getActiveSheet()const fRange = fWorksheet.getRange('A1:B2')const rangePermission = fRange.getRangePermission()const rule = await rangePermission.protect({ name: 'My protected range', allowViewByOthers: false, allowedUsers: ['user1', 'user2'],})Call rangePermission.listRules() to list the rules intersecting the range. rangePermission.unprotect() removes all intersecting rules.
Manage protected ranges
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const fWorksheet = fWorkbook.getActiveSheet()const permission = fWorksheet.getWorksheetPermission()const createdRules = await permission.protectRanges([ { ranges: [fWorksheet.getRange('D1:D4')], options: { name: 'Public area', allowViewByOthers: true }, }, { ranges: [fWorksheet.getRange('E1:E4')], options: { name: 'Private area', allowViewByOthers: false, allowedUsers: ['user1'] }, },])await createdRules[0].updateRanges([fWorksheet.getRange('D1:D5')])Diagnose why a value cannot be entered in A1
The example shows the permissions required to enter a plain cell value. Any false value blocks the edit. debugCellPermission(0, 0) returns the protection rule covering A1, or undefined if none applies.
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const worksheet = fWorkbook.getActiveSheet().getWorksheetPermission()const rule = await worksheet.debugCellPermission(0, 0)console.table({ workbookEdit: fWorkbook.getWorkbookPermission().canEdit(), worksheetEdit: worksheet.canEdit(), setCellValue: worksheet.getPoint(univerAPI.Enum.WorksheetPermissionPoint.SetCellValue), rangeEdit: rule?.canEdit() ?? true,})List of permission points
Worksheet actions and their points
Each operation checks its own points. A workbook point always applies alongside the worksheet or range points listed in the same row. When a row includes a range point, every protected range the operation touches must also allow the edit. Hiding a row or column widens the check to the whole row or column.
| Action | Required points |
|---|---|
| Enter a cell value (excluding formulas) | WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellValuePermission, RangeProtectionPermissionEditPoint |
| Insert a worksheet | WorkbookEditablePermission, WorkbookCreateSheetPermission |
| Copy a worksheet | WorkbookEditablePermission, WorkbookCopySheetPermission |
| Move a worksheet | WorkbookEditablePermission, WorkbookMoveSheetPermission |
| Rename a worksheet | WorkbookEditablePermission, WorkbookRenameSheetPermission |
| Hide or show a worksheet | WorkbookEditablePermission, WorkbookHideSheetPermission |
| Delete a worksheet | WorkbookEditablePermission, WorkbookDeleteSheetPermission |
| Hide or show rows or columns | WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetRowStylePermission or WorksheetSetColumnStylePermission, and the edit point of each intersecting protected range |
| Resize rows or columns, or fit them to their content | WorksheetSetRowStylePermission or WorksheetSetColumnStylePermission |
| Merge or unmerge cells | WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission, and the edit point of each intersecting protected range |
| Sort a range | WorkbookEditablePermission, WorksheetEditPermission, WorksheetSortPermission, and the edit point of each intersecting protected range |
| Freeze or unfreeze panes | WorkbookEditablePermission, WorksheetEditPermission |
| Show or hide gridlines, or change their color | WorkbookEditablePermission, WorksheetEditPermission |
| Add, update, or delete an annotation | WorkbookEditablePermission, WorksheetEditPermission, and the edit point of each protected range that contains the cell |
| Group or ungroup rows or columns | WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetRowStylePermission or WorksheetSetColumnStylePermission, and the edit point of each intersecting protected range |
| Create a protection rule | WorkbookCreateProtectPermission |
| Manage the collaborators of a protection rule | WorksheetManageCollaboratorPermission or RangeProtectionPermissionManageCollaPoint |
| Delete a protection rule | WorksheetDeleteProtectionPermission or RangeProtectionPermissionDeleteProtectionPoint |
When a required point is false, the command is rejected before it changes the document.
Annotations follow the cell edit points. Reading an annotation is not permission-checked.
Comment permissions
Reading a Sheets comment requires workbook View. Posting requires workbook Comment. Both require worksheet View. For a comment anchored to a cell, each protection rule covering that cell must also allow viewing. Authors can update or delete their own comments.
Workbook permissions
| API Enum | Corresponding Permission Point Class | Description |
|---|---|---|
| univerAPI.Enum.WorkbookPermissionPoint.Edit | WorkbookEditablePermission | Can edit |
| univerAPI.Enum.WorkbookPermissionPoint.View | WorkbookViewPermission | Can view |
| univerAPI.Enum.WorkbookPermissionPoint.Print | WorkbookPrintPermission | Can print |
| univerAPI.Enum.WorkbookPermissionPoint.Export | WorkbookExportPermission | Can export |
| univerAPI.Enum.WorkbookPermissionPoint.Share | WorkbookSharePermission | Can share |
| univerAPI.Enum.WorkbookPermissionPoint.CopyContent | WorkbookCopyPermission | Can copy |
| univerAPI.Enum.WorkbookPermissionPoint.DuplicateFile | WorkbookDuplicatePermission | Can duplicate |
| univerAPI.Enum.WorkbookPermissionPoint.Comment | WorkbookCommentPermission | Can comment |
| univerAPI.Enum.WorkbookPermissionPoint.ManageCollaborator | WorkbookManageCollaboratorPermission | Can manage collaborators |
| univerAPI.Enum.WorkbookPermissionPoint.CreateSheet | WorkbookCreateSheetPermission | Can create worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.DeleteSheet | WorkbookDeleteSheetPermission | Can delete worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.RenameSheet | WorkbookRenameSheetPermission | Can rename worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.MoveSheet | WorkbookMoveSheetPermission | Can move worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.HideSheet | WorkbookHideSheetPermission | Can hide worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.CopySheet | WorkbookCopySheetPermission | Can copy worksheets |
| univerAPI.Enum.WorkbookPermissionPoint.ViewHistory | WorkbookViewHistoryPermission | Can view history |
| univerAPI.Enum.WorkbookPermissionPoint.RecoverHistory | WorkbookRecoverHistoryPermission | Can recover history |
| univerAPI.Enum.WorkbookPermissionPoint.CreateProtection | WorkbookCreateProtectPermission | Can create protection |
| univerAPI.Enum.WorkbookPermissionPoint.InsertRow | WorkbookInsertRowPermission | Can insert rows |
| univerAPI.Enum.WorkbookPermissionPoint.InsertColumn | WorkbookInsertColumnPermission | Can insert columns |
| univerAPI.Enum.WorkbookPermissionPoint.DeleteRow | WorkbookDeleteRowPermission | Can delete rows |
| univerAPI.Enum.WorkbookPermissionPoint.DeleteColumn | WorkbookDeleteColumnPermission | Can delete columns |
Worksheet permissions
| API Enum | Corresponding Permission Point Class | Description |
|---|---|---|
| univerAPI.Enum.WorksheetPermissionPoint.Edit | WorksheetEditPermission | Can edit |
| univerAPI.Enum.WorksheetPermissionPoint.View | WorksheetViewPermission | Can view |
| univerAPI.Enum.WorksheetPermissionPoint.Copy | WorksheetCopyPermission | Can copy |
| univerAPI.Enum.WorksheetPermissionPoint.SetCellValue | WorksheetSetCellValuePermission | Can edit cell values |
| univerAPI.Enum.WorksheetPermissionPoint.SetCellStyle | WorksheetSetCellStylePermission | Can edit cell styles |
| univerAPI.Enum.WorksheetPermissionPoint.SetRowStyle | WorksheetSetRowStylePermission | Can set row styles |
| univerAPI.Enum.WorksheetPermissionPoint.SetColumnStyle | WorksheetSetColumnStylePermission | Can set column styles |
| univerAPI.Enum.WorksheetPermissionPoint.InsertRow | WorksheetInsertRowPermission | Can insert rows |
| univerAPI.Enum.WorksheetPermissionPoint.InsertColumn | WorksheetInsertColumnPermission | Can insert columns |
| univerAPI.Enum.WorksheetPermissionPoint.DeleteRow | WorksheetDeleteRowPermission | Can delete rows |
| univerAPI.Enum.WorksheetPermissionPoint.DeleteColumn | WorksheetDeleteColumnPermission | Can delete columns |
| univerAPI.Enum.WorksheetPermissionPoint.Sort | WorksheetSortPermission | Can sort |
| univerAPI.Enum.WorksheetPermissionPoint.Filter | WorksheetFilterPermission | Can filter |
| univerAPI.Enum.WorksheetPermissionPoint.PivotTable | WorksheetPivotTablePermission | Can use pivot tables |
| univerAPI.Enum.WorksheetPermissionPoint.InsertHyperlink | WorksheetInsertHyperlinkPermission | Can use hyperlinks |
| univerAPI.Enum.WorksheetPermissionPoint.ManageCollaborator | WorksheetManageCollaboratorPermission | Can manage collaborators |
| univerAPI.Enum.WorksheetPermissionPoint.DeleteProtection | WorksheetDeleteProtectionPermission | Can delete protection |
| univerAPI.Enum.WorksheetPermissionPoint.EditExtraObject | WorksheetEditExtraObjectPermission | Can edit extra objects |
| univerAPI.Enum.WorksheetPermissionPoint.SelectProtectedCells | WorksheetSelectProtectedCellsPermission | Can select protected cells |
| univerAPI.Enum.WorksheetPermissionPoint.SelectUnProtectedCells | WorksheetSelectUnProtectedCellsPermission | Can select unprotected cells |
Range protection
| API Enum | Corresponding Permission Point Class | Description |
|---|---|---|
| univerAPI.Enum.RangePermissionPoint.Edit | RangeProtectionPermissionEditPoint | Can edit protected ranges |
| univerAPI.Enum.RangePermissionPoint.View | RangeProtectionPermissionViewPoint | Can view content of protected ranges |
| univerAPI.Enum.RangePermissionPoint.Delete | RangeProtectionPermissionDeleteProtectionPoint | Can delete protected ranges |
| univerAPI.Enum.RangePermissionPoint.ManageCollaborator | RangeProtectionPermissionManageCollaPoint | Can manage collaborators for protected ranges |
Plugin configuration
UniverSheetsUIPlugin
protectedRangeShadowboolean | 'always' | 'non-editable' | 'non-viewable' | 'none'Default:trueWhich protected ranges show a shadow.protectedRangeUserSelectorobjectCustomize the picker used for choosing users of a protected range.componentComponentType<IPermissionDetailUserPartProps>Component that picks users.frameworkstringFramework the component uses, for examplereact.
Preset configuration
UniverSheetsCorePreset
sheetsobjectOptions for the selected feature.protectedRangeShadowboolean | 'always' | 'non-editable' | 'non-viewable' | 'none'Default:trueWhich protected ranges show a shadow.protectedRangeUserSelectorobjectCustomize the picker used for choosing users of a protected range.componentComponentType<IPermissionDetailUserPartProps>Component that picks users.frameworkstringFramework the component uses, for examplereact.
Protected range shadow strategy
Use non-editable to distinguish the protected areas the current user can edit from those they cannot. Editable areas receive no shadow, areas with editing disabled keep their shadow, and non-viewable ranges stay masked.
The setting affects only how range and worksheet protection is displayed. It does not create protection rules, does not change edit or view permissions, and does not add shadows to unprotected areas. Configure the protection rules and the current user’s permissions first, as described above.
| Strategy | Display behavior |
|---|---|
true / 'always' | Show shadows for all protected areas (default). |
'non-editable' | Hide shadows on editable protected areas; keep them on non-editable areas. |
'non-viewable' | Show shadows only on non-viewable protected areas. |
false / 'none' | Hide all protection shadows; permission checks still apply. |
Protection shadow preview
Compare the same areas under different strategies for the current user.
Unprotected
No shadow
Protected · editable
No shadow
Protected · read-only
Shadow shown
Protected · not viewable
Shadow shown
Illustration only: changing the shadow does not change permissions. Hidden content stays hidden, even with none.
Set the strategy during initialization:
univer.registerPlugin(UniverSheetsUIPlugin, { protectedRangeShadow: 'non-editable',})createUniver({ presets: [ UniverSheetsCorePreset({ sheets: { protectedRangeShadow: 'non-editable', }, }), ],})Custom user component
The built-in user selector covers a limited set of cases. When your requirements exceed it, provide a custom component:
For details on building one, see Custom Components.
univer.registerPlugin(UniverSheetsUIPlugin, { protectedRangeUserSelector: { /** * Custom component; must implement the `IPermissionDetailUserPartProps` interface. */ component: CustomPermissionDetailUserPart, /** * The framework of the component. Must be passed correctly. */ framework: 'react', },})const { univer } = createUniver({ presets: [ UniverSheetsCorePreset({ sheets: { protectedRangeUserSelector: { /** * Custom component; must implement the `IPermissionDetailUserPartProps` interface. */ component: CustomPermissionDetailUserPart, /** * The framework of the component. Must be passed correctly. */ framework: 'react', }, }, }), ],})Update permission UI with the Facade API
Protected range shadow strategy
The Facade API below changes existing workbooks in the current Univer instance. In plugin mode, import @univerjs/sheets-ui/facade first; the Sheets Core preset already includes that module.
// Set to only show shadows for non-editable rangesuniverAPI.setProtectedRangeShadowStrategy('non-editable')// Get the current protected range shadow display strategyconsole.log(univerAPI.getProtectedRangeShadowStrategy())// Subscribe to changes in the protected range shadow strategyconst subscription = univerAPI.getProtectedRangeShadowStrategy$().subscribe((strategy) => { console.log('Global strategy changed to:', strategy) // Update UI or perform other actions})// Later, unsubscribe to clean upsubscription.unsubscribe()Custom user component
Call setSelectUserList() from the change handler of your user picker. The React example below clears the selection. useDependency runs inside the component, and the service is updated only after a click. Build the remaining parts of the picker against IPermissionDetailUserPartProps.
import type { IPermissionDetailUserPartProps } from '@univerjs/sheets-ui'import type { FC } from 'react'import { SheetPermissionUserManagerService } from '@univerjs/sheets-ui'import { useDependency } from '@univerjs/ui'export const CustomPermissionDetailUserPart: FC<IPermissionDetailUserPartProps> = () => { const service = useDependency(SheetPermissionUserManagerService) const clearSelection = () => service.setSelectUserList([]) return <button type="button" onClick={clearSelection}>Clear selected users</button>}import type { IPermissionDetailUserPartProps } from '@univerjs/preset-sheets-core'import type { FC } from 'react'import { SheetPermissionUserManagerService, useDependency } from '@univerjs/preset-sheets-core'export const CustomPermissionDetailUserPart: FC<IPermissionDetailUserPartProps> = () => { const service = useDependency(SheetPermissionUserManagerService) const clearSelection = () => service.setSelectUserList([]) return <button type="button" onClick={clearSelection}>Clear selected users</button>}Hide the permission dialog
univerAPI.setPermissionDialogVisible(false)Permission service integration
Integrating a third-party authorization service (advanced)
Register your IAuthzIoService implementation before creating the workbook. The service must save protection rules and collaborator changes, return permissions for the current user, and propagate request failures to the caller.
import { IAuthzIoService, Univer } from '@univerjs/core'import { YourAuthzService } from './authorization-service'const univer = new Univer({ override: [[IAuthzIoService, { useClass: YourAuthzService }]],})Collaborator management
- Get the collaborator list
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const workbookPermission = fWorkbook.getWorkbookPermission()const collaborators = await workbookPermission.listCollaborators()console.log(collaborators)- Add collaborators
Use addCollaborator to add one person. setCollaborators replaces the entire list, so include everyone who should retain access.
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const workbookPermission = fWorkbook.getWorkbookPermission()await workbookPermission.addCollaborator( { userID: 'user1', name: 'John Doe', avatar: '' }, univerAPI.Enum.UnitRole.Editor,)- Replace the collaborator list
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const workbookPermission = fWorkbook.getWorkbookPermission()await workbookPermission.setCollaborators([ { user: { userID: 'user1', name: 'John Doe', avatar: '' }, role: univerAPI.Enum.UnitRole.Editor, }, { user: { userID: 'user2', name: 'Jane Smith', avatar: '' }, role: univerAPI.Enum.UnitRole.Reader, },])- Update collaborator roles
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const workbookPermission = fWorkbook.getWorkbookPermission()await workbookPermission.updateCollaborator( { userID: 'user1', name: 'John Doe Updated', avatar: '' }, univerAPI.Enum.UnitRole.Reader,)- Remove collaborators
const fWorkbook = univerAPI.getActiveWorkbook()if (!fWorkbook) throw new Error('No active workbook')const workbookPermission = fWorkbook.getWorkbookPermission()await workbookPermission.removeCollaborators(['user1', 'user2'])Extend permissions in a plugin
Extended usage
To check permissions inside your own plugin, work with the permission points directly.
The example below uses WorkbookEditablePermission. Other permission points follow the same pattern.
import { IPermissionService } from '@univerjs/core'import { WorkbookEditablePermission } from '@univerjs/sheets'class YourService { constructor(@IPermissionService private _permissionService: IPermissionService) { } setWorkbookNotEditable() { this._permissionService.updatePermissionPoint(new WorkbookEditablePermission('unitId').id, false) } setWorkbookEditable() { this._permissionService.updatePermissionPoint(new WorkbookEditablePermission('unitId').id, true) }}SheetPermissionCheckController.permissionCheckByPoints(points) checks an explicit list of permission points and returns false when any of them is disabled. Use it when a command already knows the points it needs, such as the points of a specific protection rule.
How to extend permission points
For custom permission points, implement IPermissionPoint and register it with the permission service:
import type { IPermissionPoint } from '@univerjs/core'import { IPermissionService, PermissionStatus } from '@univerjs/core'import { UnitAction, UnitObject } from '@univerjs/protocol'export class CustomPermissionPoint implements IPermissionPoint { type = UnitObject.Unkonwn // your type subType = UnitAction.View // your subType status = PermissionStatus.INIT value = true // Default value id: string constructor(unitId: string, subUnitId: string, customId: string) { // The id must be unique within `IPermissionService`. this.id = `${unitId}.${subUnitId}.${customId}` }}class YourService { constructor(@IPermissionService private _permissionService: IPermissionService) { this._init() } _init() { this._permissionService.addPermissionPoint(new CustomPermissionPoint('unitId', 'subUnitId', 'my-id')) }}// How to use it elsewhereclass ConsumeService { constructor(@IPermissionService private _permissionService: IPermissionService) { } doSomething() { const point = this._permissionService.getPermissionPoint(new CustomPermissionPoint('unitId', 'subUnitId', 'my-id').id) console.log(point?.value) } bindEvent() { // This returns an RxJS observable that lets you listen for permission changes const point$ = this._permissionService.getPermissionPoint$(new CustomPermissionPoint('unitId', 'subUnitId', 'my-id').id) console.log(point$) }}Reference
How is this guide?