AlbertMunichMar
AlbertMunichMar

Reputation: 1856

Alternative for appendRow in Google App Script

I have a lot of CSV files with data. With a Google App Script I add them together. The result is that I have an array of arrays in memory. I also do some filtering, and then paste the information in a new Spreadsheet. To do that, I use the appendRow method while looping:

uniqueRows.forEach(function(row) {
  outputSheet.appendRow(row);
});

Problem is, I run out of time and Google App Script crashes. Is there any alternative to solve this?

I know from Visual Basic that if you have a range, you can paste it in one step into a sheet, but now I have an array of arrays in memory. Other alternative would be, instead of pasting the information in one file, paste it in multiple files. But first I would like t know if there is a more efficient way.

Upvotes: 0

Views: 727

Answers (1)

Neven Subotic
Neven Subotic

Reputation: 1429

I assume your uniqueRows is a 2-dimensional array, where the first item contains all the values for that particular row you want to add. Then you should be able to do, get the exact range you want to start at and then write that array into the range:

var rowStart = outputSheet.getLastRow() + 1;

outputSheet
.getRange( rowStart, 1, uniqueRows.length, uniqueRows[0].length)
.setValues( uniqueRows )

Upvotes: 1

Related Questions