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

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

问题描述

ColumnA ColumnB
jhinz    115
tom      116 

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

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)

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

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

我试图用嵌套的 if 语句执行 for 循环,但它不起作用.有人可以帮我吗?

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

推荐答案

以最简单的形式并查看工作原理,您可以试试这个:

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
}

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

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