Enum ProtectionType
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
保护类型
一个枚举,表示可以保护工作表中哪些部分免遭修改。
如需调用枚举,您可以调用其父类、名称和属性。例如
SpreadsheetApp.ProtectionType.RANGE
。
// Remove all range protections in the spreadsheet that the user has permission
// to edit.
const ss = SpreadsheetApp.getActive();
const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (const protection of protections) {
if (protection.canEdit()) {
protection.remove();
}
}
// Removes sheet protection from the active sheet, if the user has permission to
// edit it.
const sheet = SpreadsheetApp.getActiveSheet();
const protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if (protection?.canEdit()) {
protection.remove();
}
属性
属性 | 类型 | 说明 |
RANGE | Enum | 对某个范围的保护。 |
SHEET | Enum | 对工作表的保护。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eProtectionType\u003c/code\u003e is an enum used to specify whether you are working with sheet or range protection in Google Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eIt has two properties: \u003ccode\u003eSHEET\u003c/code\u003e and \u003ccode\u003eRANGE\u003c/code\u003e, that are used with the \u003ccode\u003egetProtections()\u003c/code\u003e method to retrieve the corresponding protections.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003eProtectionType\u003c/code\u003e to remove or modify existing protections within your spreadsheet, given the necessary permissions.\u003c/p\u003e\n"]]],[],null,["# Enum ProtectionType\n\nProtectionType\n\nAn enumeration representing the parts of a spreadsheet that can be protected from edits.\n\nTo call an enum, you call its parent class, name, and property. For example, `\nSpreadsheetApp.ProtectionType.RANGE`.\n\n```javascript\n// Remove all range protections in the spreadsheet that the user has permission\n// to edit.\nconst ss = SpreadsheetApp.getActive();\nconst protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);\nfor (const protection of protections) {\n if (protection.canEdit()) {\n protection.remove();\n }\n}\n``` \n\n```javascript\n// Removes sheet protection from the active sheet, if the user has permission to\n// edit it.\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];\nif (protection?.canEdit()) {\n protection.remove();\n}\n``` \n\n### Properties\n\n| Property | Type | Description |\n|----------|--------|-------------------------|\n| `RANGE` | `Enum` | Protection for a range. |\n| `SHEET` | `Enum` | Protection for a sheet. |"]]