google-sheets - 具有特定格式内容的表格上的过滤功能 google-sheets
问题描述
我有这张表,上面有我想在另一个页面上过滤的匹配列表(按名称、赢/输、日期等),但是它们每个都有多行,我如何指定每个选择的格式?谢谢!
编辑:这应该是所需的结果示例:与过滤器选项匹配的多行列表(我尝试使用 filter() 但只需要我单独的行,例如:如果我通过补丁过滤它只会给我一个名字蓝色/红色草稿而不是全部 5 行)这是一个示例:https ://docs.google.com/spreadsheets/d/1NlAG6kt6RsqzOJ3HgYwmyaKqF01gM364cv8AcjDtt9o/edit?usp=sharing
解决方案
以下解决方案是关于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)
}
}
}
}
推荐阅读
- java - 查询未正确运行 - SQlite Android Studio
- batch-file - 文件不断被删除
- python - 将数据框列从文本更改为熊猫数据框中的数字
- javascript - (Js) 循环中未定义的标签元素创建
- php - php表单提交并感谢您带有他们名字的消息
- flutter - 是否可以为 3 种架构构建一个 apk?
- python - Tkinter 入口小部件验证 - 让我的代码更性感
- sql-server - 如何在 mulesoft 应用程序中启用 SQL Server 数据库的身份插入?
- python - 使用 pandas 将三个单独的 CSV 文件中的特定元素连接到一个 CSV 文件中
- c# - 如何使用实例化在玩家位置旁边生成对象