在 Google Apps Script 中,你可以使用 Protection
类来管理和删除对用户的保护。具体来说,你可以使用 removeEditors
方法来删除特定用户的编辑权限,或者使用 remove
方法来完全删除保护。
以下是一个示例,演示如何删除特定用户的编辑权限以及如何完全删除保护:
- 删除特定用户的编辑权限:
- function removeUserProtection() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); protections.forEach(function(protection) { // 假设你要删除的用户的电子邮件地址 var userEmail = 'user@example.com'; protection.removeEditors([userEmail]); }); }
- 完全删除保护:
- function removeAllProtections() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); protections.forEach(function(protection) { protection.remove(); }); }
在这两个示例中:
getProtections
方法用于获取工作表中所有的保护对象。removeEditors
方法用于删除特定用户的编辑权限。remove
方法用于完全删除保护。
你可以根据需要选择使用哪种方法。如果你只想删除特定用户的编辑权限,请使用 removeEditors
方法;如果你想完全删除保护,请使用 remove
方法。