将复选框重置为false [英] Reset checkboxes to false

查看:113
本文介绍了将复选框重置为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 for setValue().
      • But to use setValue() in the for loop leads to higher cost. So in this modification, I used setValues().
      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()

      • Reference :

        • setValue()
        • setValues()
        • 如果这不是您想要的,请告诉我。我想修改它。

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

          这篇关于将复选框重置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆