Template: protection
template_sheet_set_password(wb, sheet, password):
password |
Effect |
|---|---|
| a non-empty string | lock the sheet with that password |
"" |
remove the password but keep the protection |
null or undefined |
remove protection completely |
template_sheet_set_protection(wb, sheet, props): props is an object that uses the permission keys of
worksheet protection.
| Value | Effect |
|---|---|
true |
the action is disabled |
false |
the action is allowed |
null |
clear the key |
null instead of props |
remove all protection |
The password is informational. See Protection.
const XLSX = require("@agent-sheet/wasm");const src = XLSX.utils.book_new();XLSX.utils.book_append_sheet(src, XLSX.utils.aoa_to_sheet([[1]]), "Sheet1");const wb = XLSX.read(XLSX.write(src, { type: "buffer", bookType: "xlsx" }), { template: true });const protect = () => XLSX.read(XLSX.write(wb, { type: "buffer", bookType: "xlsx", template: true })).Sheets.Sheet1["!protect"];
XLSX.utils.template_sheet_set_password(wb, "Sheet1", "secret");console.log(!!protect());XLSX.utils.template_sheet_set_protection(wb, "Sheet1", { formatCells: false, sort: null });console.log(protect().formatCells); // false: formatting is allowedXLSX.utils.template_sheet_set_password(wb, "Sheet1", null);console.log(protect());truefalseundefined