使用谷歌应用程序脚本在电子表格的一列中获得价值 [英] get value in one column in spreadsheet using google apps script
问题描述
我想要使用Google应用程序脚本从电子表格中的一列中获取字符串值(稍后与if条件进行比较)。
我搜索了互联网,发现了这个链接 - 对不起,如果这听起来很愚蠢,我对Google应用脚本不熟悉 - https://developers.google.com/apps-script/class_spreadsheet
var values = SpreadsheetApp.getActiveSheet( ).getRange(2,3,6,4).getValues();
我想这一定很有帮助,唯一的问题是我想从列中获取值是动态的,所以我该如何设置这个列的范围?如果您使用简单的话:
var values = SpreadsheetApp.getActiveSheet()。getDataRange()。getValues()
您将得到一个由表和行列索引的所有数据的二维数组。
因此,要获得列A中的值,row1使用 values [0] [0]
, values [1] [0]
for columnA,row 2, values [0] [2]
用于C列的row1等等。
如果需要在for循环中迭代(n = 0; n
var cell = values [n] [x]; // x是从0开始的列的索引
code
$ b $ p
$ b 如果您需要在一个for循环中循环(单行):
for(n = 0; n var cell = values [x] [n]; // x是从0开始的行的索引
}
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
解决方案 if you use simply :
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.
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...
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
}
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屋!