FRangePermission

GitHubEdit on GitHub
Packages@univerjs/sheets
CORE

Implementation class for RangePermission Manages range-level permissions

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

Overview

@univerjs/sheets

MethodDescription
isProtectedCheck if the current range is protected
listRulesList all protection rules that intersect with the current range
protectProtect the current range
unprotectCancel all protection rules that intersect with the current range

APIs

Getters & Queries

isProtected

Check if the current range is protected.

Signature

isProtected(): boolean

Returns

  • 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);
Source: @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);
Source: @univerjs/sheets

Miscellaneous

protect

Protect the current range.

Signature

async protect(options?: IRangeProtectionOptions): Promise<FRangeProtectionRule>

Parameters

  • options IRangeProtectionOptions (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);
Source: @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);
Source: @univerjs/sheets