ExcelScript.WorksheetProtection interface
Represents the protection of a worksheet object.
Methods
| get |
Specifies the protection options for the worksheet. |
| get |
Specifies if the worksheet is protected. |
| protect(options, password) | Protects a worksheet. Fails if the worksheet has already been protected. |
| unprotect(password) | Unprotects a worksheet. |
Method Details
getOptions()
Specifies the protection options for the worksheet.
getOptions(): WorksheetProtectionOptions;
Returns
getProtected()
Specifies if the worksheet is protected.
getProtected(): boolean;
Returns
boolean
protect(options, password)
Protects a worksheet. Fails if the worksheet has already been protected.
protect(options?: WorksheetProtectionOptions, password?: string): void;
Parameters
Optional. Sheet protection options.
- password
-
string
Optional. Sheet protection password.
Returns
void
Examples
/**
* This script protects cells from being selected on the current worksheet.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the protection settings for the current worksheet.
const currentSheet = workbook.getActiveWorksheet();
const sheetProtection = currentSheet.getProtection();
// Create a new WorksheetProtectionOptions object with the selectionMode property set to `none`.
let protectionOptions : ExcelScript.WorksheetProtectionOptions = {
selectionMode: ExcelScript.ProtectionSelectionMode.none
}
// Apply the given protection options.
sheetProtection.protect(protectionOptions);
}
unprotect(password)
Unprotects a worksheet.
unprotect(password?: string): void;
Parameters
- password
-
string
Sheet protection password.
Returns
void
Feedback
Submit and view feedback for