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