ExcelScript.WorkbookProtection interface
Représente la protection d’un objet classeur.
Méthode
| get |
Spécifie si le classeur est protégé. |
| protect(password) | Protège le classeur. Échoue si le classeur est protégé. |
| unprotect(password) | Annule la protection du classeur. |
Détails de la méthode
getProtected()
Spécifie si le classeur est protégé.
getProtected(): boolean;
Retourne
boolean
Exemples
/**
* This script protects the workbook with a default password, if there is not already protection.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the workbook-level protection object.
const protection = workbook.getProtection();
// Check if the workbook is already protected.
if (!protection.getProtected()) {
// Apply a default password.
protection.protect("1234");
}
}
protect(password)
Protège le classeur. Échoue si le classeur est protégé.
protect(password?: string): void;
Paramètres
- password
-
string
Mot de passe de protection du classeur.
Retourne
void
Exemples
/**
* This script protects the workbook using a password given in a user prompt.
*/
function main(workbook: ExcelScript.Workbook, password?: string) {
// Get the workbook-level protection object.
const protection = workbook.getProtection();
// Protect the workbook with the given password.
// If the optional password was omitted,
// no password will be needed to unprotect the workbook.
protection.protect(password);
}
unprotect(password)
Annule la protection du classeur.
unprotect(password?: string): void;
Paramètres
- password
-
string
Mot de passe de protection du classeur.
Retourne
void
Exemples
/**
* This script removes protection from the workbook using a password given in a user prompt.
*/
function main(workbook: ExcelScript.Workbook, password?: string) {
// Get the workbook-level protection object.
const protection = workbook.getProtection();
// Unprotect the workbook with the given password.
protection.unprotect(password);
}