【发布时间】:2021-04-17 03:40:51
【问题描述】:
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 引导我做到这一点。现在我有一个问题,如果它的值为OK,该代码将自动保护 1 个单元格 F。如果F的值为OK,有没有办法保护F:G(如果F5值OK,F5:G5将受到保护)?我试过修改:
protection.addEditor(me).setUnprotectedRanges(sh.getRange("F1:G").CreateTextFinder("^(?!OK).*$").MatchEntireCell(true).useRegularExpression(true).findAll());
但它仅在值为OK 时保护单元格G。
【问题讨论】:
标签: google-apps-script google-sheets