PageProtection
已弃用。对于在新版 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 const sheet = SpreadsheetApp.getActiveSheet(); const 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 const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); const isProtected = permissions.isProtected();
返回
Boolean - 工作表是否已启用工作表保护。
另请参阅
removeUser(user)
removeUser(user)已弃用。此函数已弃用,不应在新脚本中使用。
从可修改工作表的用户列表中移除用户。
// Remove the "user@example.com" user to the list of users who can edit this // sheet const sheet = SpreadsheetApp.getActiveSheet(); const 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 const sheet = SpreadsheetApp.getActiveSheet(); const permissions = sheet.getSheetProtection(); permissions.setProtected(true); sheet.setSheetProtection(permissions);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
protection | Boolean | true 表示启用工作表保护,false 表示停用工作表保护。 |