Tengo una hoja de cálculo de la que soy propietario y tengo 10 usuarios con permiso de editor, ya que hay muchas celdas para desbloquear o bloquear, lo mejor sería bloquear todo primero y desbloquear las que pueden usar de forma segura sin editar accidentalmente una fórmula. incorrectamente
ahora solo estoy adivinando cuál sería la mejor solución. Me gustaría evitar que se eliminen los usuarios.
si importa, entonces nadie está en un grupo
estos serían los que los editores pueden editar
['B3:U27', 'W3:AP27', 'E29:E31', 'I29:I31', 'M29:M31', 'Q29:Q31', 'U29:U31', 'Z29:Z31', 'AD29:AD31', 'AH29:AH31', 'AL29:AL31', 'AP29:AP31', 'B29', 'F29', 'J29', 'N29', 'R29', 'W29', 'AA29', 'AE29', 'AI29', 'AM29', 'C29', 'G29', 'K29', 'O29', 'S29', 'X29', 'AB29', 'AF29', 'AJ29', 'AN29', 'D29', 'H29', 'L29', 'P29', 'T29', 'Y29', 'AC29', 'AG29', 'AK29', 'AO29', 'B31', 'F31', 'J31', 'N31', 'R31', 'W31', 'AA31', 'AE31', 'AI31', 'AM31', 'C31', 'G31', 'K31', 'O31', 'S31', 'X31', 'AB31', 'AF31', 'AJ31', 'AN31', 'D31', 'H31', 'L31', 'P31', 'T31', 'Y31', 'AC31', 'AG31', 'AK31', 'AO31', 'B33:C33', 'F33:G33', 'J33:K33', 'N33:O33', 'R33:S33', 'W33:X33', 'AA33:AB33', 'AE33:AF33', 'AI33:AJ33', 'AM33:AN33','D33:E33', 'H33:I33', 'L33:M33', 'P33:Q33', 'T33:U33', 'Y33:Z33', 'AC33:AD33', 'AG33:AH33', 'AK33:AL33', 'AO33:AP33'];
todo lo demás se puede bloquear
¿Se crearán 1 o 2 hojas adicionales cada día y esto se aplicará a todas las hojas a partir de ahora?
¿Importa que ya tenga algunas hojas con protección manual (sin script)?
¿Se notificará a los usuarios de esto o todo sucederá en segundo plano?
ACTUALIZAR:
Encontré el script correcto para proteger la página y desbloquear el rango y funciona perfectamente
Enlace
function testProtect() {
var sheet = SpreadsheetApp.getActiveSheet();
var protection = sheet.protect().setDescription('Sample protected sheet');
var unprotected = sheet.getRange('B3:I27');
protection.setUnprotectedRanges([unprotected]);
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
pero había dos cosas que no pude entender: ¿cómo puedo aplicarlo a todas las hojas y agregar más celdas y rangos? porque si agrego otro rango da error
var unprotected = sheet.getRange('B3:I27','F29:I29');
Excepción: B3:I27 no se puede convertir a tipo int (línea 4 en el archivo "Código")
¡Gracias de antemano por cualquier ayuda!
Solución del problema
Si entiendo bien tu publicación, este es tu objetivo:
Solución recomendada:
Puede consultar este script de muestra a continuación, donde bloquea su hoja y solo desbloquea rangos específicos que configuró.
Guión de muestra
[ACTUALIZADO]
function main(){ //Main function to run
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var disregard = ["Sheet3","Sheet4","Sheet5"]; //ADD SHEET NAMES HERE THAT YOU WANT TO BE DISREGARDED
for(var x=0; x<sheets.length; x++){
if(disregard.some(data => sheets[x].getName().includes(data))){
//E.g. Disregard any sheet names added on the "disregard" array
}else{
unlockCertainRanges(sheets[x]);
}
}
}
function unlockCertainRanges(currentSheet){ //Function to unlock certain ranges on your spreadshseet
var sheet = currentSheet;
// Remove all range protections in the spreadsheet
var protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
protection.remove();
}
var protection = sheet.protect();
//restrict editors to owner
protection.getRange().getA1Notation();
var eds = protection.getEditors();
protection.removeEditors(eds);
//set unprotected ranges
var ranges = protection.getUnprotectedRanges();
var data = ["A1:A5","B6:B10","C11:C15"]; // ADD YOUR RANGES HERE
data.forEach(res => { //LOOPS INTO EVERY ARRAY CONTAINING SPECIFIC RANGES
ranges.push(sheet.getRange(res));
protection.setUnprotectedRanges(ranges); //REMOVES THE PROTECTION ON THE RANGE
});
}
Nota:
Borrowed a snippet of script to unlock specific ranges from How to protect a sheet then unprotect specific cells as reference.
Resultado:
Hoja de muestra
Todas las celdas están bloqueadas excepto los rangos "A1:A5","B6:B10" & "C11:C15"
(contiene la palabra "Desbloquear" para visibilidad)
Otras celdas están bloqueadas
Las celdas de rango desbloqueadas son editables
No hay comentarios.:
Publicar un comentario