Reputation: 393
I am running a sheet which people can copy through running a script, on the template file I want users to only see one of the sheets which contains a button that runs a script to copy the file.
I really want to share the document as a 'View Only' file although I still want the users to edit the range where the button is so that they can click on this and run the script.
I have tried protecting sheets and removing editors through Apps Script by using the class protection but this doesn't seem to work - I created the below which I had hoped would work:
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.getSheetByName('BALANCE SHEET').protect();
ss.getSheetByName('LANDING SHEET').protect();
ss.getSheetByName('CATEGORIES').protect();
ss.getSheetByName('REMINDERS').protect();
var user = ss.getEditors();
ss.removeEditor(user);
ss.addEditor('[email protected]');
does anyone have an idea of how I can do this please?
Upvotes: 0
Views: 65
Reputation: 50462
Spreadsheet.getEditors()
returns a array of user
s, whereas removeEditor
accepts a user
(singular) as a argument. Use Array.forEach
to remove users:
const users = ss.getEditors();
users.forEach(user => ss.removeEditor(user));
Upvotes: 1