将复选框重置为false-已实现的解决方案不起作用 [英] Reset checkboxes to false - implemented solution not working

查看:64
本文介绍了将复选框重置为false-已实现的解决方案不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列复选框,用户可以将其设置为true或false-我想通过单击按钮来运行Google Apps脚本,该按钮会将所有复选框的值重置为False.

我找到了一个相关的问题,并尝试从接受的答案中实施

是否有一个简单的错误可以解释为什么它不起作用?

解决方案

  • 您想将单元格"L5:L"的复选框更改为 false .
  • 您想使用Google Apps脚本实现这一目标.

如果我的理解是正确的,那么这个答案如何?请认为这只是几个可能的答案之一.

修改点:

  • 在您的脚本中,需要修改 values [i] [j] == false; .在这种情况下,将 values [i] [j] false 进行比较.因此,当您使用此脚本时,请修改为 values [i] [j] = false; .
  • 在这种情况下,当运行 resetBoard()时,如何取消选中"L5:L"的所有复选框?

修改后的脚本:

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

参考:

如果我误解了你的问题,而这不是你想要的方向,我深表歉意.

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?

解决方案

  • 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:

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

这篇关于将复选框重置为false-已实现的解决方案不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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