简体   繁体   English

仅允许用户在使用“仅查看”类型共享时编辑特定范围

[英]Only allow users to edit a specific range whilst using a 'view only' type share

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:我曾尝试使用类保护通过 Apps 脚本保护工作表和删除编辑器,但这似乎不起作用 - 我创建了以下我希望可以工作的内容:

  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('xxx@xxx.xxx');

does anyone have an idea of how I can do this please?有没有人知道我该如何做到这一点?

Spreadsheet.getEditors() returns a array of user s , whereas removeEditor accepts a user (singular) as a argument. Spreadsheet.getEditors()返回一个user s数组,而removeEditor接受一个user (单数)作为参数。 Use Array.forEach to remove users:使用Array.forEach删除用户:

const users = ss.getEditors();
users.forEach(user =>  ss.removeEditor(user));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM