get value in one column in spreadsheet using google apps script

て烟熏妆下的殇ゞ 提交于 2019-11-28 05:01:01

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
}

much easier way to loop through the rows and get a column value.. hope that helps

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

values.forEach( function(row) {
  row[4] // column index as 4
});

Here is the script I use to get the values in a dynamic column:

var SS = SpreadsheetApp.getActiveSheet()
var Avals = SS.getRange("A1:A").getValues();
var numberOfValues = Avals.filter(String).length;
var RangeVals = SS.getRange(1,1,numberOfValues).getValues();

I've never had to change which starting row based based on a dynamic changing starting point though. Would be interested in seeing how that would be done.

Here is a similar post. Another example here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!