https://i.stack.imgur.com/7LagU.png
我已经尝试搜索一种方法,但是不太确定要搜索此问题的关键字。有没有一种方法可以命名单元格?
Sheet
或Range
,不适用于list of ranges
。因此,您无法同时保护它们。参见Protect, hide, and edit sheets。解决方法:
var sheet = SpreadsheetApp.getActiveSheet();
var range1 = sheet.getRange("E3:F3");
var protection1 = range1.protect();
var range2 = sheet.getRange("H3");
var protection2 = range2.protect();
var protections = [protection1, protection2];
protections.forEach(protection => {
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
});
参考: