我从here获取信息来创建一个脚本,该脚本将保护工作表中的单元格范围不被编辑,但也排除了用户可以输入数据的区域。我的脚本是这样的。
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:D9和A12:E12以及A24:K24
如果我简单地复制此行并将其粘贴到一个新的单元格区域,它将覆盖先前未受保护的区域,并激活我刚刚粘贴的新行。
谢谢。
发布于 2016-08-01 17:21:56
对于多个不受保护的范围,您需要在一次调用中将所有范围作为数组参数传递:
var range1 = sheet.getRange("A1:A6");
var range2 = sheet.getRange("B1:B6");
protection.setUnprotectedRanges([range1, range2]);你的问题似乎改变了,你似乎最后问的是如何限制对多个范围的访问,而不是取消对它们的保护?为此,请保护整个工作表,然后取消对相关区域的保护,以实现您所需的功能。
https://stackoverflow.com/questions/38530200
复制相似问题