我想获取一个字符串值,以便稍后使用 Google Apps 脚本将其与电子表格中仅一列的 if 条件进行比较。 我搜索了互联网,找到了这个链接 - 抱歉,如果这听起来很愚蠢,但我是 Google 应用脚本的新手 - https://developers.google.com/apps-script/class_spreadsheet
var values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
我想这一定会有帮助,唯一的问题是我想要从中获取值的列是动态的,那么如何设置该列的范围?
最佳答案
如果您简单地使用:
var 值 = SpreadsheetApp.getActiveSheet().getDataRange().getValues()
您将获得工作表中按行和列索引的所有数据的二维数组。
因此,要获取第 1 列 A 列中的值,您可以使用 values[0][0]
,对第 2 行 A 列使用 values[1][0]
, C 列 row1 的 values[0][2]
等...
如果您需要在 for 循环中进行迭代(在单列中):
for (n = 0; n < values.length; ++n) {
var cell = values[n][x] ; // x is the index of the column starting from 0
}
如果您需要在 for 循环中迭代(在单行中):
for (n = 0; n < values[0].length; ++n) {
var cell = values[x][n] ; // x is the index of the row starting from 0
}
关于javascript - 使用谷歌应用程序脚本获取电子表格中一列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14991030/