简体   繁体   English

我可以将 onEdit function 限制为 Google 表格中的复选框单元格吗?

[英]Can I limit an onEdit function to a checkbox cell in Google Sheets?

I'm creating a spreadsheet in Google Sheets to collect and analyse individual inputs.我正在 Google 表格中创建一个电子表格来收集和分析各个输入。 The idea was to have users input data on the first sheet, hit a Submit button, and have it collected in another sheet, while clearing the first sheet inputs.想法是让用户在第一张表上输入数据,点击提交按钮,然后将其收集到另一张表中,同时清除第一张表输入。 I figured it out with a button, but I learned afterwards that buttons don't work on mobile, which will be the main method of use.我用一个按钮解决了这个问题,但后来我了解到按钮在移动设备上不起作用,这将是主要的使用方法。

So, I'm wondering if there's a way to limit an 'onEdit' function to a single checkbox.所以,我想知道是否有办法将“onEdit”function 限制为单个复选框。 ie I'd like to fill in the info without any functions going off, then when the user is ready, click the checkbox to send the info, which then sets the checkbox to false, and resets the input cells.即我想在不关闭任何功能的情况下填写信息,然后当用户准备好时,单击复选框发送信息,然后将复选框设置为 false,并重置输入单元格。

Is this possible?这可能吗?

You could use something like this:你可以使用这样的东西:

function onEdit(e) {
  if(e.range.getSheet().getName()=='Sheet8') {
    if(e.range.getA1Notation()=='A1' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A1. You have less than 30 seconds to run a function here');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
    if(e.range.getA1Notation()=='A2' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A2. You have less than 30 seconds to run a function here');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
    if(e.range.getA1Notation()=='A3' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A3. You have less than 30 seconds to run a function here.');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
  }else{
    return;
  }
}

To use this you need to insert checkboxes in A1,A2 and A3.要使用它,您需要在 A1、A2 和 A3 中插入复选框。 You can add functions as shown in the code but the onEdit(e) has to complete in 30 seconds.您可以添加代码中显示的功能,但 onEdit(e) 必须在 30 秒内完成。

Personally, I would use a custom dialog to do what you are doing.就个人而言,我会使用自定义对话框来做你正在做的事情。 In that way, I have many more options since I have all the events of any html page and there's no need to use onEdit() at all.这样,我有更多选择,因为我拥有任何 html 页面的所有事件,并且根本不需要使用 onEdit()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM