如何查询Google表格列以获取特定值 [英] how to query a google sheet column for a certain value

查看:118
本文介绍了如何查询Google表格列以获取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有价值10,并且我得到了一个带有许多值的第一列ID的谷歌表。我希望运行一个脚本,通过该列中的所有值,一旦找到匹配项,它就会在该行上设置活动选择项。

解决方案

以下脚本在活动工作表的第一列中搜索值10,并在该值上设置选择(如果找到)。

  function setActive(){
var sheet = SpreadsheetApp.getActiveSheet();
var idValues = sheet.getRange(1,1,sheet.getLastRow(),1).getValues()。map(function(a){
return a [0];
} );
var row = idValues.indexOf(10)+ 1;
if(row> 0){
SpreadsheetApp.setActiveRange(sheet.getRange(row,1));
}
else {
throw new Error('Id not found');




$ b

数组idValues在应用indexOf之前被展平,因为getValues返回一列作为双数组 [[1],[2],[3]]

Let's say i have value 10, and I got a google sheet with first column id that has many values. I would like to run a script that goes through all the values in that column, and once it finds a match, it sets the active selection on that row

解决方案

The following script searches the first column of the active sheet for the value of 10, and sets the selection on that value if found.

function setActive() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var idValues = sheet.getRange(1, 1, sheet.getLastRow(), 1).getValues().map(function(a) {
    return a[0];
  });
  var row = idValues.indexOf(10) + 1;
  if (row > 0) {
    SpreadsheetApp.setActiveRange(sheet.getRange(row, 1));
  }
  else {
    throw new Error('Id not found');
  }
}

The array idValues is being flattened before applying indexOf, since a column is returned by getValues as a double array [[1], [2], [3]].

这篇关于如何查询Google表格列以获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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