API Reference

FRangeProtectionRule

Implementation class for range protection rules Encapsulates operations on a single protection rule

This class should not be instantiated directly. Use factory methods on univerAPI instead.

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

FRangeProtectionRule.canDelete

Check if the current user can delete this protection rule.

TypeScript
canDelete(): boolean

Returns

true if can delete rule, false otherwise.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Check if the first rule allows deleting the ruleconst rule = rules[0]if (rule?.canDelete()) {  console.log(    `You can delete this protection rule for this range ${rule.ranges.map((r) => r.getA1Notation()).join(', ')}`,  )}

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.canEdit

Check if the current user can edit this range.

TypeScript
canEdit(): boolean

Returns

true if editable, false otherwise.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Check if the first rule allows editingconst rule = rules[0]if (rule?.canEdit()) {  console.log(`You can edit this range ${rule.ranges.map((r) => r.getA1Notation()).join(', ')}`)}

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.canManageCollaborator

Check if the current user can manage collaborators for this range.

TypeScript
canManageCollaborator(): boolean

Returns

true if can manage collaborators, false otherwise.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Check if the first rule allows managing collaboratorsconst rule = rules[0]if (rule?.canManageCollaborator()) {  console.log(    `You can manage collaborators for this range ${rule.ranges.map((r) => r.getA1Notation()).join(', ')}`,  )}

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.canView

Check if the current user can view this range.

TypeScript
canView(): boolean

Returns

true if viewable, false otherwise.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Check if the first rule allows viewingconst rule = rules[0]if (rule?.canView()) {  console.log(`You can view this range ${rule.ranges.map((r) => r.getA1Notation()).join(', ')}`)}

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.getPoint

Get the value of a specific permission point.

TypeScript
getPoint(point: RangePermissionPoint): boolean

Parameters

  • point — Required. The range permission point to query.

Returns

true if allowed, false if denied.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Check if the first rule allows editingif (rules.length > 0) {  const rule = rules[0]  const canEdit = rule.getPoint(univerAPI.Enum.RangePermissionPoint.Edit)  console.log(canEdit)}

Types: RangePermissionPoint

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.getSnapshot

Get the current permission snapshot.

TypeScript
getSnapshot(): RangePermissionSnapshot

Returns

Snapshot of all permission points.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Get the permission snapshot of the first ruleif (rules.length > 0) {  const rule = rules[0]  const snapshot = rule.getSnapshot()  console.log(snapshot)}

Types: RangePermissionSnapshot

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.id

Get the rule ID.

TypeScript
readonly id: string

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.options

Get the protection options.

TypeScript
readonly options: IRangeProtectionOptions

Types: IRangeProtectionOptions

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.permissionId

Get the permission ID associated with this rule.

TypeScript
readonly permissionId: string

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.ranges

Get the protected ranges.

TypeScript
readonly ranges: FRange[]

Types: FRange

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.remove

Delete the current protection rule.

TypeScript
remove(): Promise<boolean>

Returns

A promise resolving to whether the rule was removed.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Remove the first protection ruleif (rules.length > 0) {  const rule = rules[0]  const result = await rule.remove()  console.log(result)}

Types: Promise

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.setPoint

Set a specific permission point for the range rule (low-level API).

Important: This method only updates the permission point value for an existing protection rule. It does NOT create permission checks that will block actual editing operations. You must call protect() first to create a protection rule before using this method.

This method is useful for:

  • Fine-tuning permissions after creating a protection rule with protect()
  • Dynamically adjusting permissions based on runtime conditions
  • Advanced permission management scenarios
TypeScript
setPoint(point: RangePermissionPoint, 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.

Throws

If no protection rule exists for this range.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:B2')// First, create a protection ruleconst rule = await fRange.getRangePermission().protect({ name: 'My Range', allowEdit: true })// Then you can dynamically update permission pointsawait rule.setPoint(univerAPI.Enum.RangePermissionPoint.Edit, false) // Now disable editawait rule.setPoint(univerAPI.Enum.RangePermissionPoint.View, true) // Ensure view is enabled

Types: Promise · RangePermissionPoint

Package: @univerjs/sheets · Type definitions

FRangeProtectionRule.updateRanges

Update the protected ranges.

TypeScript
updateRanges(ranges: FRange[]): Promise<boolean>

Parameters

  • ranges — Required. New ranges to protect.

Returns

A promise resolving to whether the protected ranges were updated.

Examples

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const rules = await fWorksheet.getWorksheetPermission().listRangeProtectionRules()// Update the ranges to A1:C3 for the first ruleif (rules.length > 0) {  const rule = rules[0]  const result = await rule.updateRanges([fWorksheet.getRange('A1:C3')])  console.log(result)}

Types: Promise · FRange

Package: @univerjs/sheets · Type definitions

How is this guide?

© 2026 DreamNum Co., Ltd.