Class PageProtection

页面保护

已弃用。对于在新版 Google 表格中创建的电子表格,请改用功能更强大的 Protection 类。虽然此类已废弃,但仍可供使用,以便与旧版 Google 表格兼容。

在旧版 Google 表格中访问和修改受保护的工作表。

方法返回类型简介
addUser(email)void将用户添加到可以修改工作表(如果受保护)的用户列表中。
getUsers()String[]返回可以修改此工作表的用户的电子邮件地址列表。
isProtected()Boolean指示工作表是否已启用工作表保护。
removeUser(user)void从可以修改工作表的用户列表中移除用户。
setProtected(protection)void设置工作表的保护状态。

已弃用的方法

已弃用。此函数已废弃,不应在新脚本中使用。

将用户添加到可以修改工作表的用户列表(如果工作表处于受保护状态)。

// 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);

参数

名称类型说明
emailString要添加的用户的电子邮件地址。

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

返回可以修改此工作表的用户的电子邮件地址列表。

如果工作表保护功能处于停用状态,则此调用返回的值毫无意义。

返回

String[] - 可以修改此工作表的用户的电子邮件地址的数组


已弃用。此函数已废弃,不应在新脚本中使用。

指示工作表是否已启用工作表保护。

// Determine whether or not sheet protection is enabled
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
const isProtected = permissions.isProtected();

返回

Boolean - 工作表是否已启用工作表保护

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

从可以修改工作表的用户列表中移除用户。

// 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);

参数

名称类型说明
userString要移除的用户的电子邮件地址。

另请参阅


已弃用。此函数已废弃,不应在新脚本中使用。

设置工作表的保护状态。

// Enables sheet protection for  this sheet
const sheet = SpreadsheetApp.getActiveSheet();
const permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);

参数

名称类型说明
protectionBooleantrue 用于启用工作表保护,false 用于停用工作表保护。

另请参阅