【问题标题】:Locking Cell after entering Data only once via Google Apps Script通过 Google Apps 脚本仅输入一次数据后锁定单元格
【发布时间】:2020-12-25 12:45:03
【问题描述】:

我目前正在制作一张 Google 表格,我必须与其他用户共享以进行编辑。但我希望在任何用户在 C 列的任何单元格中输入数据后,单元格被锁定,用户无法编辑单元格,而只能编辑工作表的所有者。我认为这将由 Google Apps Script 完成。下面的脚本会做我想要的,但对于整张纸。我希望它仅应用于 C 列。任何帮助将不胜感激。

[链接]Autolock Google Sheets cells after the first entry

【问题讨论】:

  • 你好@Roomi!我了解到,您获取了链接的示例代码,对其进行了修改并应用,以实现您将其应用到 C 列的目标。请与我们分享您的发现,以便我们大家看看。

标签: google-apps-script google-sheets


【解决方案1】:

感谢您的反馈,我已经能够根据我的要求修改代码。如果您只想对一列而不是整个工作表应用验证,这里是 Code 的更新版本:

   function protectOnEdit(event) {

  var range = event.range;
  var Col= parseInt(range.getColumn());
  console.log(Col);
  
  if(Col==3)
  {
  var timeZone = Session.getScriptTimeZone();
  var stringDate = Utilities.formatDate(new Date(), timeZone, 'dd/MM/yy HH:mm');
  var description = 'Protected on ' + stringDate;
  var protection = range.protect().setDescription(description);

 
  var me = Session.getEffectiveUser();
  //user who installed trigger

  protection.addEditor(me);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 2013-09-12
    相关资源
    最近更新 更多