a really quick question... I want to read rows in sheets one by one, (preferably 'live' so rather than putting it in an array or something). Besides using a loop, how do I read the contents of a whole row? Is it even possible?
Asked
Active
Viewed 2.9k times
6
-
Possible duplicate of [Retrieve rows from spreadsheet data using google app script](http://stackoverflow.com/questions/10518084/retrieve-rows-from-spreadsheet-data-using-google-app-script) – Sujay Phadke Mar 20 '17 at 12:24
-
You might consider setting up a separate sheet that will filter the row you are interested in instead of using Google Apps scripts. – ScampMichael Mar 20 '17 at 16:33
3 Answers
2
var
spreadsheetID =
"1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
rowNum = 1,
rowVals =
SpreadsheetApp.openById(spreadsheetID)
.getRange(rowNum +":"+ rowNum)
.getValues()
;
The other answers to date don't get a row, they get a range of specfic columns within a row. The code in this answer gets the entire unbounded row.

Matthew
- 757
- 11
- 19
-
This still seems to be returning an array within an array, no? I did sheet.getRange('1:1').getValues() and I had to access the inner array with [0]. – Rivers Cuomo Jan 02 '22 at 23:10
-
1
Not sure exactly what your end goal is, but I assume you mean something like this:
var values = sheet.getRange(startRow, startCol, numRows, numCols).getValues(); // returns 2d array
values.forEach(function(row){
Logger.log(row); // prints the contents of the row
});
You could also use the getCell() method of the Range class to iterate over cells in a range. The return type for getCell() is also Range. See this thread for details on the implementation Google Spreadsheets: Iterate over range, append string to each

Community
- 1
- 1

Anton Dementiev
- 5,451
- 4
- 20
- 32