Adrien Hingert
Adrien Hingert

Reputation: 1516

Google App Script: modify array before setting values in Google Sheet

I'm using Google's App Script to import AdSense data into a Google Sheet (I'm using this script and it's working fine).

Here is sample data I receive (usually the rows number in the hundreds) which is held by the variable report:

{rows=[
    {cells=[
        {value=2023-08-24}, {value=18628}, {value=32779}, {value=83}, {value=0.31}, {value=0.0045}, {value=1.39}, {value=25.81}
    ]}, 
    {cells=[
        {value=2023-08-25}, {value=11534}, {value=20630}, {value=49}, {value=0.29}, {value=0.0042}, {value=1.25}, {value=14.45}
    ]}
]}

And here is the App Script code which appends the data to Google Sheets:

sheet.getRange(2, 1, report.rows.length, 8)
      .setValues(report.rows.map((row) => row.cells.map((cell) => cell.value)));

All of this works fine.
My question is: what is the most computing-efficient way of adding multiple cells (columns) to this data (in between the given cells)? The content of each cell/column is the same for every row.
If possible, I would like to avoid for loops

Upvotes: 0

Views: 109

Answers (0)

Related Questions