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);
}
}
完美,伟大工程!谢谢 –