How to set sheet protected during google script running -


this question google spreadsheet. have spreadsheet shares multiple people. i'm using script update sheet contents well. question when running script, there way protect sheet against others edit it. , when script done, editing permission can granted users again?

i'm replying because see haven't had others yet, , i've tinkered issue without success. though in case objective different in needed code executed users when ran menu-driven scripts. since need modify protection yourself, might find works you.

in case, can forsee situation users may mid-edit when run code, prove frustrating them! might want grips user object , associated methods in order manage them. right can't see how without kicking them out (same result), maybe else chime in thoughts. take on spreadsheet class following:

  • geteditors / removeeditor / addeditor
  • getviewers / addviewers

https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet

below function made worked me (owner), not users - hope helps:

//target = string name of sheet change permissions //protecton = boolean: true = turn on protection //function returns boolean representing previous permissions setting (for loops/verification)  function sheetprotectionset(target, protecton) {   var g_wkbactive = spreadsheetapp.getactivespreadsheet();   var wkstarget = g_wkbactive.getsheetbyname(target);   var permissions = wkstarget.getsheetprotection();   var cur_protection = permissions.isprotected();    permissions.setprotected(protecton);   wkstarget.setsheetprotection(permissions);   return cur_protection; } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -