首页 > 解决方案 > 具有特定格式内容的表格上的过滤功能 google-sheets

问题描述

我有这张表,上面有我想在另一个页面上过滤的匹配列表(按名称、赢/输、日期等),但是它们每个都有多行,我如何指定每个选择的格式?谢谢! 在此处输入图像描述

编辑:这应该是所需的结果示例:与过滤器选项匹配的多行列表(我尝试使用 filter() 但只需要我单独的行,例如:如果我通过补丁过滤它只会给我一个名字蓝色/红色草稿而不是全部 5 行)这是一个示例:https ://docs.google.com/spreadsheets/d/1NlAG6kt6RsqzOJ3HgYwmyaKqF01gM364cv8AcjDtt9o/edit?usp=sharing

我在寻找什么(非相关过滤器):在此处输入图像描述

我得到了什么:在此处输入图像描述

标签: google-sheets

解决方案


以下解决方案是关于Apps Script的一个简单示例,说明如何使用简单的触发器 onEdit()以及获取设置值来实现此目的。我刚刚在Patch下拉列表中实现了这一点,但这也说明了其他项目的情况。

以下代码具有不言自明的注释:

function onEdit(e) {
  // Get both sheets
  var sheet = SpreadsheetApp.getActive().getSheetByName('Stats');
  var matchSheet = SpreadsheetApp.getActive().getSheetByName('Match History');


  // check if the cell modified is the right cell on the right sheet
  if(e.range.getColumn()==3 && e.range.getRow()==6 && e.source.getActiveSheet().getSheetName()==='Stats'){

    // Get all the values available for patch
    var patches = matchSheet.getRange(3,2,matchSheet.getLastRow(),1).getValues().flat();

    // iterate over all the patches values
    for(i=0;i<patches.length;i++){

      // if there is a match with the selected value from the dropdown
      if(patches[i]===e.range.getValue()){
        // get the range of the next 5 rows and the next 10 columns from the original sheet
        // each patch is a merge of 5 rows, thus taking the next 5 rows as the range
        var pasteValues = matchSheet.getRange(i+ 3,2,5,10).getValues();
        // append these values in the row after the last written cell in the right place of stats
        sheet.getRange(sheet.getLastRow()+1,2,5,10).setValues(pasteValues)
      }
    }

  }
  
}


推荐阅读