Javascript 有没有一种方法可以使用谷歌脚本设置特定范围的编辑器?

Javascript 有没有一种方法可以使用谷歌脚本设置特定范围的编辑器?,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我正试图为工作表上的某个范围设置编辑器。我发现了一个名为getEditors()的函数,它给出了某个定义范围内所有编辑器的列表。我们也可以设置编辑器吗 该类具有不同的方法,允许您修改的编辑器。 要设置编辑器,可以使用以下方法:删除 编辑器,使用 : // Protect range A1:B10, then remove all other users from the list of editors. var ss = SpreadsheetApp.getActive(); var range

我正试图为工作表上的某个范围设置编辑器。我发现了一个名为getEditors()的函数,它给出了某个定义范围内所有编辑器的列表。我们也可以设置编辑器吗

该类具有不同的方法,允许您修改的编辑器。 要设置编辑器,可以使用以下方法:删除 编辑器,使用

:

// 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 throws an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
  protection.setDomainEdit(false);
}