问题
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 withfalse. So when you use this script, please modify tovalues[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