如何使用Google脚本锁定当前用户的工作表

时间:2016-07-27 22:26:35

标签: google-apps-script google-sheets

我试图通过Google脚本锁定工作表。我想将此脚本锁定给所有用户。 我正在使用我在文档中找到的内容:https://developers.google.com/apps-script/reference/spreadsheet/protection

// Protect range A1:B10, then remove all other users from the list of editors.
 var ss = SpreadsheetApp.getActive();
 var range = ss.getRange('A1:B10');
 var protection = range.protect().setDescription('Sample protected range');

 // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
 // permission comes from a group, the script will throw an exception upon removing the group.
 var me = Session.getEffectiveUser();
 protection.addEditor(me);
 protection.removeEditors(protection.getEditors());
 if (protection.canDomainEdit()) {
   protection.setDomainEdit(false);
 }

问题是应该锁定工作表的脚本是由应该看到工作表锁定的用户运行的。

我的问题是:如何使用Google脚本锁定当前用户的工作表?

2 个答案:

答案 0 :(得分:1)

不要以为你能做到这一点..我尝试了但是没有用。 在我看来,访问是由用户提供的,因此您不能限制用户自己启动/运行脚本。这有点棘手

答案 1 :(得分:0)

你做不到。见https://developers.google.com/apps-script/reference/spreadsheet/protection#removeeditorsemailaddresses

关键句:“电子表格的所有者和当前用户均无法删除。”

希望我们能。

相关问题