has anyone found a way to restrict copy/download/print access for a spreadsheet using google apps script? Background info: I created a script which restricts share rights for editors using setShareableByEditors(false). The only problem is that editors can still easily make a copy of the spreadsheet and then share it widely. I know that there's an option to manually restrict this setting in Google Sheets, but this solution is not scalable as I'm trying to manage share settings for a high number of spreadsheets. Any advice would be greatly appreciated. Thank you!
3
votes
2 Answers
4
votes
You can do this by enabling and using the Advanced Drive Service. You would set the file
's restricted
label to true
. Here's an example:
function restrictFile() {
var id = '10iM3V2q7FQWBAxy93eN9jvbp_SFco-KLPibeG9XRr71';
// get the file with the Advanced Drive API (REST V2)
var file = Drive.Files.get(id);
Logger.log('File "%s", restricted label was: %s', file.title, file.labels.restricted);
// set the restricted label
file.labels.restricted = true;
//update the file
Drive.Files.update(file, id);
// check the updated file
var updatedFile = Drive.Files.get(id);
Logger.log('File "%s", restricted label is: %s', updatedFile.title, updatedFile.labels.restricted);
}
You can confirm it also in the UI under File > Share... > Advanced: