ws.protection
WorksheetProtection
Sub-API for worksheet protection operations.
9 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, 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
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