google-sheetsgoogle-apps-scriptgoogle-sheets-api

Using Sheets.Spreadsheets.Values.update() Correctly


I've created an array that I'd like to have pasted on a sheet in cell A1. I'm aware of how to do that using setValues() but I was under the impression that using Sheets.Spreadsheets.Values.update() would be faster.

So I guess that's my first question. Is it faster? My array, we'll call updatedArr consists of 70K rows by 35 columns of data.

I just can't seem to figure out how to paste this array using that method. Here is my attempt:

Sheets.Spreadsheets.Values.update({ updatedArr }, tss.getId(), `'` + clickerDataSht.getName() + `'!A1`, { valueInputOption: "USER_ENTERED" });

The error I get:

GoogleJsonResponseException: API call to sheets.spreadsheets.values.update failed with error: Invalid JSON payload received. Unknown name "updatedArr" at 'data': Cannot find field.

Is there something I need to be doing to that array?


Solution

  • Modification points:

    If your value of updatedArr is a 2-dimensional array, how about the following modification?

    From:

    Sheets.Spreadsheets.Values.update({ updatedArr }, tss.getId(), `'` + clickerDataSht.getName() + `'!A1`, { valueInputOption: "USER_ENTERED" });
    

    To:

    Sheets.Spreadsheets.Values.update({ values: updatedArr }, tss.getId(), `'${clickerDataSht.getName()}'!A1`, { valueInputOption: "USER_ENTERED" });
    

    Note:

    References: