Using checkboxes to trigger various scripts, then clear

前端 未结 1 1204
盖世英雄少女心
盖世英雄少女心 2021-01-24 11:27

I have a Google Sheet set up with two buttons on the Form sheet, which are attached to two different scripts. They work perfectly on PC, but unfortunately, custom buttons still

相关标签:
1条回答
  • 2021-01-24 12:03

    A you correctly said, running scripts on button clicks does not appear to work on the Android mobile app. This is an issue that has already been reported (see this and this). A common workaround used to be using Android add-ons but they are now deprecated.

    In order to make your script run using checkbox, one thing you can do is to modify your onEdit function. After the following modifications, it will check whether any of the checkboxes is enabled, run the appropiate function based on that, and then disable it again. You can see the updated onEdit function below:

    function onEdit(e) {
      var isAutofill = SpreadsheetApp.getActiveSheet().getRange("G3").getValue();
      var isUpdate = SpreadsheetApp.getActiveSheet().getRange("G5").getValue();
    
      if (isAutofill && isUpdate) {
        Browser.msgBox("You cannot autofill and update at once!");
        SpreadsheetApp.getActiveSheet().getRange("G3").setValue(false);
        SpreadsheetApp.getActiveSheet().getRange("G5").setValue(false);
      } else if (isAutofill) {
        AUTOFILL();
        SpreadsheetApp.getActiveSheet().getRange("G3").setValue(false);
      } else if (isUpdate) {
        UPDATE();
        SpreadsheetApp.getActiveSheet().getRange("G5").setValue(false);
      }
    
      if (e.range.getA1Notation() == 'D3') {
        if (/^\w+$/.test(e.value)) {        
          eval(e.value)();
          e.range.clearContent();
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题