处理将保护同时应用于多个范围 [英] Processing apply protection on multiple ranges all together

查看:68
本文介绍了处理将保护同时应用于多个范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近添加了以编程方式操纵保护范围的功能.但是,当它们具有相同的保护以应用保护而不是一次处理一个范围时,是否有办法将多个范围全部加在一起?以下代码来自Google示例脚本.目前,我正在运行以下代码,数量与我拥有的范围一样多.有更好的方法一次完成所有操作吗?

Recently ability to manipulate protection for a range programatically has been added. But is there a way to add multiple ranges all together when they have same protection to apply protection instead of processing each range one at a time? The following code is from Google sample script. Currently I am running the following code as many as ranges I have. Is there a better way to do it all at once?

var ss = SpreadsheetApp.getActive();
var range = ss.getRange('A1:B10');
var protection = range.protect().setDescription('Sample protected range');

// 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('Sample protected sheet');
var unprotected = sheet.getRange('B2:C5');
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);
}

谢谢.

推荐答案

中括号[]:

protection.setUnprotectedRanges([unprotected]);

建议使用数组.您是否尝试过:

suggests that an array is expected. Have you tried:

protection.setUnprotectedRanges([sheet.getRange("B2:B5"),
  sheet.getRange("F2:F5"),
  sheet.getRange("H2:H5")]);

这篇关于处理将保护同时应用于多个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆