繁体   English   中英

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

[英]How to lock a sheet for current user with Google script

我正在尝试通过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脚本锁定当前用户的工作表?

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

你不能 请参阅https://developers.google.com/apps-script/reference/spreadsheet/protection#removeeditorse电子邮件地址

关键句子: “电子表格的所有者和当前用户都不能删除。”

希望我们能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM