function Lock(){
var sh = SpreadsheetApp.openById(ssID).getSheetByName('6');
var protection = sh.protect().setDescription('BVDATA');
var me = Session.getEffectiveUser();
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:F").createTextFinder("^(?!OK).*$").matchEntireCell(true).useRegularExpression(true).findAll());
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()){
protection.setDomainEdit(false);
}
}
@Tanaike 引导我这样做。现在我有一个问题,该代码将自动保护 1 个单元格 F 如果值为OK
。如果 F 的值为? ,对我来说有没有办法保护它F:G
(就像F5:G5
如果F5
value将被保护OK
)OK
。我尝试修改:
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:G").CreateTextFinder("^(?!OK).*$").MatchEntireCell(true).useRegularExpression(true).findAll());
但它仅保护单元G当该值OK
。
我相信你的目标如下。
OK
.为了实现这一点,下面的修改如何?
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:F").createTextFinder("^(?!OK).*$").matchEntireCell(true).useRegularExpression(true).findAll());
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:F").createTextFinder("^(?!OK).*$").matchEntireCell(true).useRegularExpression(true).findAll().map(r => r.offset(0, 0, 1, 2)));
offset
。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句