I want to code my Google Sheets sheet or multiple tabs in a sheet in a way that it automatically locks at a specific time every day and unlock it on specific time every day. Also I should be able to edit it, but not my collaborators.
How do I pull this off?
Thank you!
CodePudding user response:
there are several ways to go ahead. the simplest ist probably to add and remove your collaborators
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
//set the hours in which you want the document to be edited
var starttime = 8
var endtime = 18
//instead Europe/Berlin (your place)
var now = Utilities.formatDate(new Date(), "Europe/Berlin", "H")
//adds a collaborator
if (now >= starttime && now <= endtime){
ss.addEditor("[email protected]")
}
//removes a collaborator & optionally gives him viewing rights
else{
ss.removeEditor("[email protected]")
//ss.addViewer("[email protected]")
}
}
now run your code every hour with a trigger and it will do the rest by itself.