我正在尝试在google工作表中设置不受保护的范围,我有相当多的范围要同时取消保护。因此,我希望将它们存储在一个数组中,然后同时取消对它们的保护。但是,我在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);
}
}发布于 2017-09-27 01:01:53
通过名称unprotected将整个array传递给方法setUnprotectedRanges()
function myFunction2() {
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect().setDescription('Protect Sheet');
var unprotected = [];
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);
...
}https://stackoverflow.com/questions/46424572
复制相似问题