【问题标题】:How to lock a sheet for current user with Google script如何使用 Google 脚本为当前用户锁定工作表
【发布时间】:2016-12-02 03:03:27
【问题描述】:

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

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      希望我们可以。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-17
        相关资源
        最近更新 更多