1 google-sheets google-apps-script
我在 googlesheet 中编写一些 JavaScript 代码时遇到问题,该代码将找到该工作表的所有当前编辑者(除了所有者之外)并删除他们的编辑写入。目前我一直在尝试使用:
//remove the current editors and only allow the origional owner to have access.
var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadSheet.removeEditor(SpreadSheet.getEditors())
Run Code Online (Sandbox Code Playgroud)
这会出现一个“无效电子邮件:”,其中包含一串编辑电子邮件。有没有办法可以分离此电子邮件字符串,然后通过循环运行“removeEditor”代码以获取需要删除的所需数量的编辑器?
小智 6
看起来您正在尝试将数组传递到需要单个用户的函数中。根据GAS API,getEditors()返回Users数组。该removeEditor()函数需要电子邮件地址或用户对象。尝试循环遍历数组以删除编辑器:
var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var editors = SpreadSheet.getEditors();
for (var i = 0; i < editors.length; i++) {
SpreadSheet.removeEditor(editors[i]);
};
Run Code Online (Sandbox Code Playgroud)