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?
Please have a look at the documentation: getLastColumn() and to get the maximum count including empty ones, getMaxColumns().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With