FRangePermission
| Packages | @univerjs/sheets |
|---|
Implementation class for RangePermission Manages range-level permissions
This class should not be instantiated directly. Use factory methods on
univerAPIinstead.
Overview
@univerjs/sheets
| Method | Description |
|---|---|
isProtected | Check if the current range is protected |
listRules | List all protection rules that intersect with the current range |
protect | Protect the current range |
unprotect | Cancel all protection rules that intersect with the current range |
APIs
Getters & Queries
isProtected
Check if the current range is protected.
Signature
isProtected(): booleanReturns
boolean— True if the range is protected, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
// Check if the A1:B2 range is protected
const isProtected = fRange.getRangePermission().isProtected();
console.log(isProtected);@univerjs/sheets
listRules
List all protection rules that intersect with the current range.
Signature
async listRules(options?: {
ignoreCollaborators?: boolean; // Option to ignore fetching collaborators for performance
}): Promise<FRangeProtectionRule[]>Parameters
options{ ignoreCollaborators?: boolean; }(optional) — No description
Returns
Promise<FRangeProtectionRule[]>— Array of protection rules.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const rules = await fRange.getRangePermission().listRules();
console.log(rules);@univerjs/sheets
Miscellaneous
protect
Protect the current range.
Signature
async protect(options?: IRangeProtectionOptions): Promise<FRangeProtectionRule>Parameters
optionsIRangeProtectionOptions(optional) — No description
Returns
Promise<FRangeProtectionRule>— The created protection rule.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const rule = await fRange.getRangePermission().protect({
name: 'My protected range',
allowedUsers: ['user1', 'user2'],
allowViewByOthers: false,
});
console.log(rule);@univerjs/sheets
unprotect
Cancel all protection rules that intersect with the current range.
Signature
async unprotect(): Promise<boolean>Returns
Promise<boolean>— True if all rules were successfully removed, false otherwise.
Examples
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fRange = fWorksheet.getRange('A1:B2');
const result = await fRange.getRangePermission().unprotect();
console.log(result);@univerjs/sheets