javascript - 在 Google 表格中使用多个条件过滤值
问题描述
我正在使用下面的公式从第 1 页过滤 H 列中的 OK 值并粘贴到第 2 页
function filter() {
const sss = SpreadsheetApp.getActiveSpreadsheet();
const ss = sss.getSheetByName('Page1'); //replace with source Sheet tab name
const rawData = ss.getRange("A2:I150").getValues().map(([a,,c,d,e,f,g,h]) => [a,c,d,e,f,g,h]); // code [a,c,d,e,f,g]
const frawData=rawData.filter(row=>row[6]!="OK");// 5 means column G. [a,c,d,e,f,g] => [0,1,2,3,4,5]
const tss = SpreadsheetApp.getActiveSpreadsheet();
const ts = tss.getSheetByName('Page2'); //replace with destination Sheet tab name
ts.getRange(2, 1, frawData.length, frawData[0].length).setValues(frawData);
}
我有另一个场景
我还需要使用值为 1 的 I 列进行过滤所以,我应该得到第 4 行值,因为它包含 H 列 OK 和 I 列 1
解决方案
不知道你为什么使用!="OK"
并说该行应该包含“OK”。
所以可能你需要而不是这个:
const frawData=rawData.filter(row=>row[6]!="OK");
尝试这个:
const frawData=rawData.filter(row => row[6] == "OK" && row[7] == 1);
推荐阅读
- sql - 从一列计算记录,其中值不同
- jquery - 页面在 jQuery 中轻微滚动时跳转
- bash - 在 Jenkins 中如何使用带有交叉编译环境的 Docker 镜像
- android - 安卓导航。从嵌套图片段弹出到外部片段
- graphql - 从自省选项卡 graphql 获取有关查询的信息
- javascript - 在 for 循环中使用 @ref 获取元素引用
- c++ - Windows 10 夜灯是如何实现的?
- neo4j - 在 Neo4j 中,查询以检索短于某个长度的子链
- java - 无法在 Spring 中为集成测试配置模块 - 没有可用的任务
- bash - 使用 bash 将路由器配置部分转换为 csv 文件