Reset checkboxes to false - implemented solution not working

南楼画角 提交于 2020-04-16 03:38:07

问题


I have a column of checkboxes which the user can set to true or false - I want to run a Google Apps Script on the click of a button which resets the value of all the checkboxes to False.

I found a related question, and attempted to implement the solution from the accepted answer. Unfortunately, it doesn't seem to work as intended, and I don't know enough about Apps Script to understand why. Here is my code (barely modified from Tanaike's solution):

function resetBoard() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var dataRange = sheet.getRange('L5:L');
  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;
      }
    }
  }

  dataRange.setValues(values);
}

Here is the sheet - the checkboxes in Column L are the ones I'm trying to reset. After I press the button to execute the script, it says that the script is finished, but nothing has changed:

Is there a simple mistake that explains why this isn't working?


回答1:


  • You want to change the checkboxes of the cells "L5:L" to false.
  • You want to achieve this using Google Apps Script.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

Modification points:

  • In your script, values[i][j] == false; is required to be modified. In this case, values[i][j] is compared with false. So when you use this script, please modify to values[i][j] = false;.
  • In this case, when resetBoard() is run, how about unchecking all checkboxes of "L5:L"?

Modified script:

function resetBoard() {
  SpreadsheetApp.getActiveSheet().getRange('L5:L').uncheck();
}

Reference:

  • uncheck()

If I misunderstood your question and this was not the direction you want, I apologize.



来源:https://stackoverflow.com/questions/60929703/reset-checkboxes-to-false-implemented-solution-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!