首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类保护脚本

类保护脚本
EN

Stack Overflow用户
提问于 2016-07-22 23:26:19
回答 1查看 93关注 0票数 0

我从here获取信息来创建一个脚本,该脚本将保护工作表中的单元格范围不被编辑,但也排除了用户可以输入数据的区域。我的脚本是这样的。

代码语言:javascript
复制
function myFunction() {
    // Protect the active sheet except B2:C5, then remove all other users from the list of editors.
    var sheet = SpreadsheetApp.getActiveSheet();
    var protection = sheet.protect().setDescription('2016-07-21 Material Request Form Template');
    var unprotected = sheet.getRange('C9:D9');
    protection.setUnprotectedRanges([unprotected]);
    // 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);
    }
}

var unprotected = sheet.getRange('C9:D9');这一行,这确实会在受保护的工作表中解锁这个范围,但是我还想限制这个文档中的其他范围。如何输入或修改此行,以便锁定多个范围,即C9:D9A12:E12以及A24:K24

如果我简单地复制此行并将其粘贴到一个新的单元格区域,它将覆盖先前未受保护的区域,并激活我刚刚粘贴的新行。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-08-01 17:21:56

对于多个不受保护的范围,您需要在一次调用中将所有范围作为数组参数传递:

代码语言:javascript
复制
var range1 = sheet.getRange("A1:A6");
var range2 = sheet.getRange("B1:B6");

protection.setUnprotectedRanges([range1, range2]);

你的问题似乎改变了,你似乎最后问的是如何限制对多个范围的访问,而不是取消对它们的保护?为此,请保护整个工作表,然后取消对相关区域的保护,以实现您所需的功能。

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

https://stackoverflow.com/questions/38530200

复制
相关文章

相似问题

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