0
我試圖在谷歌表中設置不受保護的範圍,我有相當多的範圍同時解除保護。因此,我想將它們存儲在一個數組中,然後同時取消所有保護。但是,我在使用protection.setUnprotectedRanges語句中的數組時遇到問題(在下面的代碼中顯示***)。protection.setUnprotectedRanges - 谷歌應用程序腳本
我可以在不聲明其中的每個元素的情況下使用數組嗎?
感謝
function myFunction2() {
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect().setDescription('Protect Sheet');
var unprotected = new Array(26);
unprotected[0] = sheet.getRange(1,1,10,1);
unprotected[1] = sheet.getRange(1,5,10,2);
unprotected[2] = sheet.getRange(1,20,10,2);
protection.setUnprotectedRanges([unprotected[]]); // *** How to I use the whole array with setUnprotectedRanges, without declaring every element within the array in the statement (as below)
//protection.setUnprotectedRanges([unprotected[0],unprotected[1]]); // don't want to use this method
// Ensure the current user is an editor before removing others. Otherwise, if the user's edit
// permission comes from a group, the script will throw an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
完美,偉大工程!謝謝 –