使用谷歌应用程序脚本获取电子表格中一列的值 [英] get value in one column in spreadsheet using google apps script

查看:22
本文介绍了使用谷歌应用程序脚本获取电子表格中一列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Google 应用程序脚本仅从电子表格中的一列获取字符串值 - 稍后将其与 if 条件进行比较.我在互联网上搜索并找到了此链接 - 抱歉,如果这听起来很愚蠢,我是 Google 应用程序脚本的新手 - https://developer.google.com/apps-script/class_spreadsheet

I want to get a string value -to compare it later on with an if condition- from only one column in spreadsheet using Google apps script. I searched the internet and I found this link - sorry if this sounds stupid, I am new to Google apps scripts - https://developers.google.com/apps-script/class_spreadsheet

var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues(); 

我想这一定很有帮助,唯一的问题是我想从中获取值的列是动态的,所以我该如何设置此列的范围

I guess that must be helpful, the only problem is that the column I want to get the values from is dynamic so how do I set the range of this column

推荐答案

如果你只是使用 :

var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues()

您将获得工作表中按行和列索引的所有数据的二维数组.

You will get a 2 Dimension array of all the data in the sheet indexed by rows and columns.

所以要获得 A 列第 1 行中的值,您使用 values[0][0]values[1][0] 用于 columnA,第 2 行,values[0][2] 列 C row1 等...

So to get the value in column A, row1 you use values[0][0] , values[1][0] for columnA, row 2, values[0][2] for column C row1, etc...

如果您需要在 for 循环中迭代(在单列中):

If you need to iterate in a for loop (in a single column) :

for(n=0;n<values.length;++n){
var cell = values[n][x] ; // x is the index of the column starting from 0
}

如果您需要在 for 循环中迭代(在一行中):

If you need to iterate in a for loop (in a single row) :

for(n=0;n<values[0].length;++n){
var cell = values[x][n] ; // x is the index of the row starting from 0
}

这篇关于使用谷歌应用程序脚本获取电子表格中一列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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