将复选框重置为false [英] Reset checkboxes to false
问题描述
我有一个Google电子表格,其中A列的每一行都有复选框。我已经编写了一个脚本来在选中了复选框的所有行上执行功能,但是我想在最后添加一个重置功能,以便在脚本运行后再次取消选中所有复选框。
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 to add in at the end a reset function so that all checked boxes are unchecked again after the script is run.
我尝试使用如下所示的for循环:
I've tried using a for loop like this:
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].setValue(false);
}
}
}
但显然这不是
有人知道怎么做吗?
推荐答案
此修改如何?我认为针对您的情况有几种解决方案。因此,请将此视为其中之一。
How about this modification? I think that there are several solutions for your situation. So please think of this as one of them.
- 出现此问题的原因是
values [i] .setValue(false);
。values [i]
是一个数组。请使用setValue()
的范围。
- 但是在for循环中使用
setValue()
会导致更高的成本。因此,在此修改中,我使用了setValues()
。
- The reason of the issue is
values[i].setValue(false);
.values[i]
is an array. Please use the range forsetValue()
.- But to use
setValue()
in the for loop leads to higher cost. So in this modification, I usedsetValues()
.
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
参考文献:
- setValue()
- setValues()
- setValue()
- setValues()
Reference :
如果这不是您想要的,请告诉我。我想修改它。
If this was not what you want, please tell me. I would like to modify it.
这篇关于将复选框重置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- But to use
- 但是在for循环中使用