Google 具有 Google Apps 脚本的电子表格用户权限

Google Spreadsheet User permission with Google Apps Script

我无法使用 GOOGLE APPS 脚本代码复制 这些操作的结果(参见图片)。

操作如下:

使用 Google 电子表格打开电子表格

右键单击 -> 保护范围...

点击这个

然后点击这个

我通过尝试此代码 NO 成功:

SpreadsheetApp.addEditor('theEmailThatIWantToEnabled@email.com');

这里是这个问题的解决方案。

在我的具体情况下,权限是 "by sheets"NOT "by ranges".

这里是一个小的工作代码:

var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
      protections[i].addEditor('theEmailYouWantEnabled@email.com');      
    }