【问题标题】:Google Sheet Script : This operation is not supported on a range with a filtered-out row谷歌表格脚本:在过滤掉行的范围内不支持此操作
【发布时间】:2021-05-03 08:31:40
【问题描述】:

这是我的问题:

由于以下行,我的下面的代码不起作用: current.uncheck();

并且日志说:“此操作在具有过滤行的范围上不受支持。”

但是这张表不应该包含过滤器,我也尝试删除潜在的过滤器但没有成功。

if(current.isChecked()) // If the check box is checked
{
  // I put some data in a array :
  var arraySupport = rangeColumnToArray(ss.getSheetByName("import_support").getRange("A1:A15"))

  var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Copy of Data Bank");

  // I change criteria filter on other sheet :
  var criteriaSupport = SpreadsheetApp.newFilterCriteria()
      .setHiddenValues(arraySupport)
      .build();  
  dataSheet.getFilter().setColumnFilterCriteria(24, criteriaSupport);
  
  ss.getRange("G5:G").clearContent();  // clear eventual content
  copyExo();  // This fonction copy one column from the filtered sheet (dataSheet) on activeSheet
  activeSheet.getFilter().remove();  // I try that without success
  current.uncheck(); // And I try to uncheck the checkbox
}

感谢您为我提供的所有帮助。

【问题讨论】:

  • 不幸的是,虽然我不确定current 与 if 语句中使用的范围之间的关系,例如,在您的情况下,当 current.uncheck(); 放在// I put some data in a array : 的行,这是您期望的结果吗?如果这不是您期望的方向,我很抱歉。
  • 事实上,tanaike,您的解决方案有效,我可以接受,但我想了解问题所在。当前为var current = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell()。过滤后的数据在工作表中,我将其复制到当前工作表中。事实上,错误似乎来自于电流受到过滤的事实,而在这张纸上似乎没有过滤器
  • 感谢您的回复。我很高兴你的问题得到了解决。当您的问题解决后,您可以将其发布为答案吗?这样,它对遇到相同问题的其他用户很有用。
  • 不知道怎么做,我投票给你的答案。
  • 感谢您的回复。根据您的回复,我将其发布为答案。这样,您可以接受它,我认为您的问题和答案对其他用户也有用。

标签: google-apps-script checkbox filter google-sheets-api filtered


【解决方案1】:

虽然我不确定current 与if 语句中使用的范围之间的关系,但为了使current.uncheck() 工作,我想提出以下修改。

修改脚本:

if(current.isChecked()) // If the check box is checked
{
  current.uncheck();  // <--- "current.uncheck();" at the last line in this function is moved to here.
  // I put some data in a array :
  var arraySupport = rangeColumnToArray(ss.getSheetByName("import_support").getRange("A1:A15"))

注意:

  • 虽然我不确定copyExo() 的详细脚本,但我认为在您的脚本中,如果current 在您的if 语句中的脚本中没有更改,则最后一行的current.uncheck() 有效。例如,当您想确认它时,将if (current) console.log(current.getA1Notation()) 放在脚本的每一行如何?这样,当current的值发生变化时,可以在日志中看到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2018-10-26
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多