ws.protection
WorksheetProtection
Sub-API for worksheet protection operations.
16 methods
isProtected
→ Promise<boolean>isProtected(): Promise<boolean>;Check whether the sheet is currently protected. @returns True if the sheet is protected
protect
→ Promise<void>protect(password?: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
Protect the sheet with an optional password. @param password - Optional password to require for unprotection
protectWithOptions
→ Promise<void>protectWithOptions(password?: string, options?: ProtectionOptions): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
| options | ProtectionOptions | optional |
Protect the sheet with an optional password and granular permission options. @param password - Optional password to require for unprotection @param options - Granular permissions (e.g., allowSort, allowFormatCells)
unprotect
→ Promise<boolean>unprotect(password?: string): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
Unprotect the sheet. Returns true if unprotection succeeded. @param password - Password if the sheet was protected with one @returns True if the sheet was successfully unprotected
canEditCell
→ Promise<boolean>canEditCell(row: number, col: number): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| row | number | required |
| col | number | required |
Check whether a specific cell can be edited under current protection. Returns true if the sheet is unprotected or the cell is unlocked. @param row - Row index (0-based) @param col - Column index (0-based) @returns True if the cell is editable
canEditCellFast
→ true | 'unknown'canEditCellFast(row: number, col: number): true | 'unknown';| Parameter | Type | Required |
|---|---|---|
| row | number | required |
| col | number | required |
Synchronous protection fast path for edit-entry commands. Returns true only when the mirror proves the sheet is currently unprotected. Returns 'unknown' for protected sheets, where callers must use canEditCell(row, col) so cell lock state remains kernel-owned.
canDoStructureOp
→ Promise<boolean>canDoStructureOp(operation: ProtectionOperation): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| operation | ProtectionOperation | required |
Check whether a structural operation is allowed under current protection. @param operation - Operation name (e.g., 'sort', 'insertRows', 'deleteColumns') @returns True if the operation is allowed
canSort
→ Promise<boolean>canSort(): Promise<boolean>;Check whether sorting is allowed under current protection. Convenience shorthand for `canDoStructureOp('sort')`. @returns True if sorting is allowed
getConfig
→ Promise<ProtectionConfig>getConfig(): Promise<ProtectionConfig>;Get the full protection configuration for the sheet. @returns Protection configuration including status and permission flags
getSelectionMode
→ Promise<'normal' | 'unlockedOnly' | 'none'>getSelectionMode(): Promise<'normal' | 'unlockedOnly' | 'none'>;Get the current selection mode when the sheet is protected. @returns 'normal' (all cells selectable), 'unlockedOnly' (only unlocked cells), or 'none' (no selection)
setSelectionMode
→ Promise<void>setSelectionMode(mode: 'normal' | 'unlockedOnly' | 'none'): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| mode | 'normal' | 'unlockedOnly' | 'none' | required |
Set the selection mode for when the sheet is protected. Only takes effect when the sheet is actually protected. @param mode - Selection mode
pauseProtection
→ Promise<void>pauseProtection(password?: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
Temporarily suspend sheet protection. If the sheet is password-protected, the correct password must be provided. @param password - Password if the sheet is password-protected
resumeProtection
→ Promise<void>resumeProtection(): Promise<void>;Re-enable previously paused protection with the original configuration.
checkPassword
→ Promise<boolean>checkPassword(password?: string): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
Check if the given password matches the current protection password without modifying protection state. @param password - Password to check @returns True if the password matches
setPassword
→ Promise<void>setPassword(password?: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| password | string | optional |
Change the protection password without needing to unprotect/re-protect. @param password - New password, or undefined/empty to remove the password
updateOptions
→ Promise<void>updateOptions(options: Partial<ProtectionOptions>): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| options | Partial<ProtectionOptions> | required |
Update protection options without needing to unprotect/re-protect. @param options - Partial protection options to merge with existing options