2017-09-26 1 views
0

J'essaie de configurer des plages non protégées dans une feuille Google, j'ai plusieurs plages à déprotéger en même temps. Par conséquent, je voudrais les stocker dans un tableau et ensuite déprotéger tous en même temps. Cependant, j'ai des problèmes pour utiliser le tableau dans l'instruction protection.setUnprotectedRanges (indiqué par *** dans le code ci-dessous). Puis-je utiliser un tableau sans déclarer tous les éléments qu'il contient?protection.setUnprotectedRanges - Script Google Apps

Merci

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); 
} 
} 

Répondre

0

passer l'ensemble array par son nom unprotected dans 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); 
    ... 
} 
+0

parfait, fonctionne très bien! Je vous remercie –