samedi 28 février 2015

Add an Editor for script to run, then Remove them - temporary Editor permission


I shared a spreadsheet with a sheet named "times". This sheet is range protected to other users, but them must view and have to sort it in several ways. I create some menus with menuEntries.push etc... wrote the scripts for sort this sheet in all the ways i need, but only people I set as administrator can sort using my menu. The others can't to do it cause they can't execute the script on range protected. I would like to grant permission to everybody only during the script exectuting, the code should sound something like this above ( that don't works )



function Editors() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var targetSheet = ss.getSheetByName("times");
var user = SpreadsheetApp.getActive().getEditors();
var permission = targetSheet.getSheetProtection();
permission.addUser(user);
SpreadsheetApp.flush();

var tableRange = "orario!b7:ap209";
var tableRange = "times";
var range = ss.getRange(tableRange);
range.sort( { column: 2, ascending: true } );

permission.removeUser(user)
targetSheet.setSheetProtection(permission)
}


...if someone can help me .... thanks in advance....





Aucun commentaire:

Enregistrer un commentaire