FRangePermission
Implementation class for RangePermission Manages range-level permissions
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
FRangePermission.isProtected
Check if the current range is protected.
isProtected(): booleanReturns
True if the range is protected, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:B2')// Check if the A1:B2 range is protectedconst isProtected = fRange.getRangePermission().isProtected()console.log(isProtected)Package: @univerjs/sheets · Type definitions
FRangePermission.listRules
List all protection rules that intersect with the current range.
listRules(options?: { ignoreCollaborators?: boolean; }): Promise<FRangeProtectionRule[]>Parameters
options— Optional. Options for listing protection rules.
Returns
Array of protection rules.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:B2')const rules = await fRange.getRangePermission().listRules()console.log(rules)Types: FRangeProtectionRule · Promise
Package: @univerjs/sheets · Type definitions
FRangePermission.protect
Protect the current range.
protect(options?: IRangeProtectionOptions): Promise<FRangeProtectionRule>Parameters
options— Optional. Protection options.
Returns
The created protection rule.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:B2')const rule = await fRange.getRangePermission().protect({ name: 'My protected range', allowedUsers: ['user1', 'user2'], allowViewByOthers: false,})console.log(rule)Types: FRangeProtectionRule · Promise · IRangeProtectionOptions
Package: @univerjs/sheets · Type definitions
FRangePermission.unprotect
Cancel all protection rules that intersect with the current range.
unprotect(): Promise<boolean>Returns
True if all rules were successfully removed, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1:B2')const result = await fRange.getRangePermission().unprotect()console.log(result)Types: Promise
Package: @univerjs/sheets · Type definitions
How is this guide?