【问题标题】:Autolock Google Sheets cells after the first entry第一次输入后自动锁定 Google 表格单元格
【发布时间】:2019-01-01 23:53:07
【问题描述】:

我正在尝试将 Google 表格用作我的业务的销售登记册。但是,关于信息的输入,我想配置一个具体的细节,但还没有整理出来。

我创建了一个表格,您可以在其中输入所有信息(例如日期、售出物品、总金额等)。一切都与桌子完美搭配。但是,我希望它在输入所述信息后立即自动阻止对任何单元格中的信息进行任何更改。假设有人输入一个数量,然后选择另一个单元格并尝试再次更改数量,但由于保护原因无法更改。

我在某个时间在这里找到了一些关于自动锁定的信息:Locking cells in Google Sheets at a specific time 但这不是我需要的。另外,我是初学者,我认为 Google 表格中的某些内容已经发生了变化,因为我无法让它工作,即使是在时间锁定的情况下。我非常感谢您能提供的任何帮助。

【问题讨论】:

    标签: google-sheets google-sheets-formula


    【解决方案1】:

    您可以尝试为以下代码安装 on edit 触发器。

    它将从任何和所有已编辑范围中删除所有编辑器(安装触发器的用户和工作表的所有者除外)。它还会为保护添加描述,以便您知道何时完成。

    function protectOnEdit(event) {
    
      var range = event.range;
      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);
    
      // below code taken directly from Google's documentation (second comment is my own):
    
      // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
      // permission comes from a group, the script throws an exception upon removing the group.
    
      var me = Session.getEffectiveUser();
      //user who installed trigger
    
      protection.addEditor(me);
      protection.removeEditors(protection.getEditors());
      if (protection.canDomainEdit()) {
        protection.setDomainEdit(false);
      }
    }
    

    Reference

    【讨论】:

    • 谢谢,我试试看
    猜你喜欢
    • 2022-08-04
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2022-11-16
    相关资源
    最近更新 更多