Reset checkboxes to false

前端 未结 4 1207
Happy的楠姐
Happy的楠姐 2020-12-06 19:09

I have a Google spreadsheet where column A has checkboxes in each row. I have written a script to perform a function on all rows where the checkboxes are checked, but I want

相关标签:
4条回答
  • 2020-12-06 19:16

    By highlighting all the cells in the range that you want to "uncheck" hold Crtl and double tap the spacebar.

    0 讨论(0)
  • 2020-12-06 19:17

    How about this modification? I think that there are several solutions for your situation. So please think of this as one of them.

    Modification points :

    • The reason of the issue is values[i].setValue(false);. values[i] is an array. Please use the range for setValue().
      • But to use setValue() in the for loop leads to higher cost. So in this modification, I used setValues().
    • Put "false" to values, if values[i][j] is "true".
    • Put the modified values to the sheet using setValues().

    Modified script :

    var dataRange = sheet.getRange('A3:A');
    var values = dataRange.getValues();
    for (var i = 0; i < values.length; i++) {
      for (var j = 0; j < values[i].length; j++) {
        if (values[i][j] == true) {
          values[i][j] = false; // Modified
        }
      }
    }
    dataRange.setValues(values); // Added
    

    Reference :

    • setValue()
    • setValues()

    If this was not what you want, please tell me. I would like to modify it.

    0 讨论(0)
  • 2020-12-06 19:22

    This solution posted above does reset all checkboxes; however, it also unexpectedly changes cells with the value of 1 in it to FALSE.

    I want to make a script to reset checkboxes on ALL sheets...

    function resetCheckBoxesAllSheets() {
    var ss = SpreadsheetApp.getActive();
    var allsheets = ss.getSheets();
    for (var s in allsheets){
    var sheet=allsheets[s]
    
    var dataRange = sheet.getRange('A4:Z100');
    var values = dataRange.getValues();
    for (var i = 0; i < values.length; i++) {
      for (var j = 0; j < values[i].length; j++) {
        if (values[i][j] == true) {
          values[i][j] = false; // Modified
        }
      }
    }
    dataRange.setValues(values);
    
    
    }//end of  sheets loop.
    }// end of function...
    
    0 讨论(0)
  • 2020-12-06 19:36

    Alternatively, Since you want to uncheck everything in the range (and all of the range have checkboxes in them), just do:

    sheet.getRange('A3:A').setValue(false);
    

    without checking/looping.

    0 讨论(0)
提交回复
热议问题