How to restrict copy/download/print access for a file using Google apps script

↘锁芯ラ 提交于 2021-01-01 04:01:40

问题


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!


回答1:


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:




回答2:


It is only possible to restrict commenters and viewers from copy/download/print. It is not possible to restrict editors in the same way unfortunately.



来源:https://stackoverflow.com/questions/42103407/how-to-restrict-copy-download-print-access-for-a-file-using-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!