编写谷歌Javascript类似于vlookup [英] Writing google Javascript similar to vlookup

查看:115
本文介绍了编写谷歌Javascript类似于vlookup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ColumnA ColumnB 
jhinz 115
tom 116

这个代码背后的想法是有人输入一个数字(比如说116),计算机在B列中查找它并返回列A中的名字(汤姆)



我需要代码帮助的唯一部分是计算机在列116中查找值。

我正在尝试使用for循环嵌套如果语句,但它不工作。
有人可以帮我吗?



感谢您的任何建议。



Jenny

解决方案

以最简单的形式看到工作原则,你可以试试这个:

  function findinB(){
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var last = ss.getLastRow();
var data = sh.getRange(1,1,last,2).getValues(); //从列A和B创建一个数据数组$ b $ valB = Browser.inputBox('Enter value (nn = 0; nn if(data [nn] [1] == valB){break}; //搜索B')
如果找到列B中的一个匹配,则打破循环
}
Browser.msgBox(data [nn] [0]); //显示列A
}


ColumnA ColumnB
jhinz    115
tom      116 

The idea behind this code is someone enters a number (lets say 116), the computer looks it up in column B and returns the name in column A (tom)

The only part I need help on for the code is the computer looking up the value in column 116.

I was trying to do a for loop with a nested if statement but it wasn't working. Could someone help me?

Thank you for any advice.

Jenny

解决方案

in its simplest form and to see the working principle you could try this :

function findinB() {
  var sh = SpreadsheetApp.getActiveSheet();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var last=ss.getLastRow();
  var data=sh.getRange(1,1,last,2).getValues();// create an array of data from columns A and B
  var valB=Browser.inputBox('Enter value to search in B')
  for(nn=0;nn<data.length;++nn){
    if (data[nn][1]==valB){break} ;// if a match in column B is found, break the loop
      }
Browser.msgBox(data[nn][0]);// show column A
}

这篇关于编写谷歌Javascript类似于vlookup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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