簡體   English   中英

基於單元格值的 Google 工作表保護

[英]Google sheet protect based on cell value

我在一個谷歌表格文件中有 30 個標簽,它們都具有相同的結構但數據不同

我想要一個根據值鎖定(保護)整個工作表的腳本

此值被定義為范圍,如果該值是(已審核),我想鎖定選項卡

  • 單元格位置:A5
  • 單元格值:“已審核”
function protectAudited() {
  var ss=SpreadsheetApp.getActive();
  var shts=ss.getSheets();
  shts.forEach(function(sh) {
    if(sh.getRange('A5').getValue()=='audited') {
      sh.protect();
    }
  });
}

也許像這樣:

function protectAudited() {
  var ss=SpreadsheetApp.getActive();
  var shts=ss.getSheets();
  shts.forEach(function(sh) {
    if(sh.getRange('A5').getValue()=='Audited') {
      sh.protect();
    }else {
      var protection=sh.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
      if(protection && protection.canEdit()) {
        protection.remove();
      }
    }
  });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM