Google 工作表保护的应用程序脚本,并授予多个用户的编辑权限

问题描述 投票:0回答:1

我需要帮助获取代码来保护 Google 工作表,并为多个用户提供编辑权限以编辑受保护的工作表。我已经尝试了下面的代码,但我能够允许自己进行编辑,但我无法添加其他电子邮件地址以允许他们编辑工作表。

function protectRange() {
// Protect the active sheet except 1:1 & A:A, then remove all other users from the list of editors.
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect().setDescription('Protected sheet');
protection.setUnprotectedRanges([sheet.getRange('1:1'),sheet.getRange('A:A')]);

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

我已经尝试更改 protection.addEditor(me) 行;并添加一个数组 protection.addEditors([me,'[email protected]','[email protected]']);

但它不起作用。我能做什么?

非常感谢。干杯

arrays google-apps-script permissions editor spreadsheet-protection
1个回答
0
投票

虽然我不确定我是否能正确理解你的情况,关于

I have tried to change the line for protection.addEditor(me); and add an array protection.addEditors([me,'[email protected]','[email protected]']);
,当我看到你的脚本时,即使你使用
protection.addEditors([me,'[email protected]','[email protected]'])
而不是
protection.addEditor(me)
,由
protection.removeEditors(protection.getEditors())
,编辑被删除。我认为这可能是您遇到问题的原因。

这样的话,下面的修改怎么样?

来自:

var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());

致:

var me = Session.getEffectiveUser();
protection.removeEditors(protection.getEditors());
protection.addEditors([me.getEmail(), '[email protected]', '[email protected]']);
© www.soinside.com 2019 - 2024. All rights reserved.