第一次输入后自动锁定Google表格单元格 [英] Autolock Google Sheets cells after the first entry

查看:62
本文介绍了第一次输入后自动锁定Google表格单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将Google表格用作我的业务的销售记录.但是,我想配置一个关于信息输入的特定细节,但是还无法对其进行整理.

I'm trying to use Google Sheets as a sales register for my business. However, there is a specific detail I'd like to configure about the input of information, but couldn't sort it out yet.

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

I created a table where you enter all the information (such as the date, item sold, total amount, etc.). Everything works perfectly with the table. However, I would like it to automatically prevent any changes to the information in any cell, right after said information has been entered. Let's say someone puts a quantity, then chooses another cell and tries to change the quantity again, but can't due to the protection.

我在某个时间找到了一些有关自动锁定的信息:在特定时间锁定Google表格中的单元格,但这不是我所需要的.另外,我还是一个初学者,我认为Google表格中的某些内容已经发生了变化,因为即使按时间锁定,我也无法使其正常工作.非常感谢您能提供的任何帮助.

I found some information about autolock at a certain time here: Locking cells in Google Sheets at a specific time but that's not what I need. Also, I'm a beginner and I think some things have changed in Google Sheets because I couldn't make it work, even with the lock by time. I would really appreciate any help you can offer.

推荐答案

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

You could try installing an on edit trigger for the below code.

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

It will remove all editors (except for the user that installs the trigger and the owner of the sheet) from any and all edited ranges. It will also add a description to the protection so you'll know when it was done.

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

参考

这篇关于第一次输入后自动锁定Google表格单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆