2015-09-10 45 views
1

我無法在Google表格中找到所有當前編輯器(除了所有者之外)並刪除其編輯寫入的JavaScript代碼。目前我一直在嘗試使用:如何使用腳本從Google桌面中刪除編輯器

//remove the current editors and only allow the origional owner to have access. 
var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet(); 
SpreadSheet.removeEditor(SpreadSheet.getEditors()) 

這想出了一個「無效的電子郵件:」與編輯電子郵件的字符串。有沒有辦法將這個電子郵件字符串分開,然後通過一個循環運行「removeEditor」代碼以獲取需要刪除的編輯器數量?

回答

2

它看起來像你試圖傳遞一個數組到一個函數,期望單個用戶。根據GAS API,getEditors()返回一組用戶。 removeEditor()函數需要電子郵件地址或用戶對象。嘗試通過您的陣列循環刪除編輯器:

var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet(); 
var editors = SpreadSheet.getEditors(); 
for (var i = 0; i < editors.length; i++) { 
    SpreadSheet.removeEditor(editors[i]); 
    }; 
+0

謝謝!那是我正在尋找的那個。我非常喜歡它在下面的變化中使用它: //刪除當前的編輯器並使其成爲查看者,並且只允許原始擁有者訪問。 var DocEditors = SpreadSheet.getEditors() for(DocEditors中的n)if(DocEditors [n]!= OrigionalEmail){SpreadSheet.removeEditor(DocEditors [n]);} } – Abardak

相關問題