页面 保护
已弃用。对于在新版 Google 表格中创建的电子表格,请改用功能更强大的 Protection
类。虽然此类已废弃,但仍可用于与旧版 Google 表格兼容。
在旧版 Google 表格中访问和修改受保护的工作表。
已弃用的方法
方法 | 返回类型 | 简介 |
---|---|---|
| void | 将用户添加到可以修改工作表的名单中(如果工作表受保护)。 |
| String[] | 返回可修改相应工作表的用户电子邮件地址列表。 |
| Boolean | 指示工作表是否已启用工作表保护功能。 |
| void | 从可修改工作表的用户列表中移除用户。 |
| void | 设置工作表的保护状态。 |
已弃用的方法
add User(email)
add User(email)
已弃用。此函数已弃用,不应在新脚本中使用。
将用户添加到可以修改工作表的受保护用户列表中。
// Add the "[email protected]" user to the list of users who can edit this sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.addUser('[email protected]'); permissions.setProtected(true); sheet.setSheetProtection(permissions);
参数
名称 | 类型 | 说明 |
---|---|---|
email | String | 要添加的用户的电子邮件地址。 |
另请参阅
get Users()
get Users()
已弃用。此函数已弃用,不应在新脚本中使用。
返回可修改相应工作表的用户电子邮件地址列表。
如果工作表保护处于停用状态,则此调用返回的值毫无意义。
返回
String[]
- 可以修改相应工作表的用户电子邮件地址数组。
is Protected()
is Protected()
已弃用。此函数已弃用,不应在新脚本中使用。
指示工作表是否已启用工作表保护功能。
// Determine whether or not sheet protection is enabled const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); const isProtected = permissions.isProtected();
返回
Boolean
- 工作表是否已启用工作表保护。
另请参阅
remove User(user)
remove User(user)
已弃用。此函数已弃用,不应在新脚本中使用。
从可修改工作表的用户列表中移除用户。
// Remove the "[email protected]" user to the list of users who can edit this // sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.removeUser('[email protected]'); permissions.setProtected(true); sheet.setSheetProtection(permissions);
参数
名称 | 类型 | 说明 |
---|---|---|
user | String | 要移除的用户的电子邮件地址。 |
另请参阅
set Protected(protection)
set Protected(protection)
已弃用。此函数已弃用,不应在新脚本中使用。
设置工作表的保护状态。
// Enables sheet protection for this sheet const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.setProtected(true); sheet.setSheetProtection(permissions);
参数
名称 | 类型 | 说明 |
---|---|---|
protection | Boolean | true 表示启用工作表保护,false 表示停用工作表保护。 |