Sunday, May 19, 2024
64
rated 0 times [  68] [ 4]  / answers: 1 / hits: 26861  / 11 Years ago, sat, november 30, 2013, 12:00:00

I want to use the number of columns in a sheet in a for loop. I could use a function like this, to stop when the loop finds the first empty column:



function getRowAsArray(sheet, row) {
var dataRange = sheet.getRange(row, 1, 1, 99);
var data = dataRange.getValues();
var columns = [];

for (i in data) {
var row = data[i];

Logger.log(Got row, row);

for(var l=0; l<99; l++) {
var col = row[l];
// First empty column interrupts
if(!col) {
break;
}

columns.push(col);
}
}

return columns;
}


But I'd like an alternative function which use the number of columns in the sheet. How can I do that?


More From » google-apps-script

 Answers
20

Please have a look at the documentation:
getLastColumn() and to get the maximum count including empty ones, getMaxColumns().


[#73972] Friday, November 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ericmaximilianz

Total Points: 252
Total Questions: 118
Total Answers: 87

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;