Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 基于单元格值的googlesheet保护_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 基于单元格值的googlesheet保护

Google apps script 基于单元格值的googlesheet保护,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我在一个谷歌工作表文件中有30个标签,它们都有相同的结构,但数据不同 我想要一个脚本,它根据值锁定(保护)整个工作表 该值定义为范围,如果该值是(已审核的),我希望锁定该选项卡 单元格位置:A5 单元格值:“已审核” 也许是这样的: function protectAudited() { var ss=SpreadsheetApp.getActive(); var shts=ss.getSheets(); shts.forEach(function(sh) { if(sh

我在一个谷歌工作表文件中有30个标签,它们都有相同的结构,但数据不同

我想要一个脚本,它根据值锁定(保护)整个工作表

该值定义为范围,如果该值是(已审核的),我希望锁定该选项卡

  • 单元格位置:A5
  • 单元格值:“已审核”
也许是这样的:

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();
      }
    }
  });
}

many thnx bro,最后一个问题:D,取消保护选项卡的功能是什么?以下是
//从活动工作表中删除工作表保护的示例,如果用户有权编辑它。var sheet=SpreadsheetApp.getActiveSheet();var保护=sheet.getProtections(电子表格app.ProtectionType.sheet)[0];if(protection&&protection.canEdit()){protection.remove();}
如何在else部分的代码中使用它函数protectAudited(){var ss=SpreadsheetApp.getActive();var shts=ss.getSheets();shts.forEach(函数(sh){if(sh.getRange('A5').getValue()=“Done”){sh.protect().setDescription(“关闭财务后无法编辑文件”);}否则{***解除保护}};}
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();
      }
    }
  });
}