首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >protection.setUnprotectedRanges -谷歌应用脚本

protection.setUnprotectedRanges -谷歌应用脚本
EN

Stack Overflow用户
提问于 2017-09-26 18:57:37
回答 1查看 1.1K关注 0票数 0

我正在尝试在google工作表中设置不受保护的范围,我有相当多的范围要同时取消保护。因此,我希望将它们存储在一个数组中,然后同时取消对它们的保护。但是,我在protection.setUnprotectedRanges语句中使用数组时遇到了问题(如下面代码中的*所示)。

我可以在不声明数组中的每个元素的情况下使用数组吗?

谢谢

代码语言:javascript
复制
 function myFunction2() {

 var sheet = SpreadsheetApp.getActiveSheet();
 var protection = sheet.protect().setDescription('Protect Sheet');
var unprotected = new Array(26);

 unprotected[0] = sheet.getRange(1,1,10,1);
 unprotected[1] = sheet.getRange(1,5,10,2);
 unprotected[2] = sheet.getRange(1,20,10,2);

 protection.setUnprotectedRanges([unprotected[]]); // *** How to I use the whole array with setUnprotectedRanges, without declaring every element within the array in the statement (as below)
 //protection.setUnprotectedRanges([unprotected[0],unprotected[1]]); // don't want to use this method
 // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
 // permission comes from a group, the script will throw an exception upon removing the group.
 var me = Session.getEffectiveUser();
 protection.addEditor(me);
 protection.removeEditors(protection.getEditors());
 if (protection.canDomainEdit()) {
   protection.setDomainEdit(false);
 }
}
EN

回答 1

Stack Overflow用户

发布于 2017-09-27 01:01:53

通过名称unprotected将整个array传递给方法setUnprotectedRanges()

代码语言:javascript
复制
function myFunction2() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var protection = sheet.protect().setDescription('Protect Sheet');
  var unprotected = [];

  unprotected[0] = sheet.getRange(1,1,10,1);
  unprotected[1] = sheet.getRange(1,5,10,2);
  unprotected[2] = sheet.getRange(1,20,10,2);

  protection.setUnprotectedRanges(unprotected);
  ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46424572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档