Google Sheets, writing array to sheet via script


I’ve a sheet which I’m using arrays in the script (to save on time)

I have no problems writing a 2d Array to my sheets, however for some reason I can’t get a 1D array to write properly

This is a screenshot in debug mode of my array.
It’s just a list of prices (500 rows)

This is my code (I added in the log to show the counts)

Logger.log (costPerItem.length) 

I just want to put the data into the 12th column on the tab that I’ve called shWorkspace earlier in the code.

But I get the error:

Exception: The parameters (number[]) don’t match the method signature for SpreadsheetApp.Range.setValues.

And I can’t figure out why.

I’ve used almost identical code:


To apply a 2d array and this works fine

>Solution :

Posting a flattened array as a column

let a = => [e]);
sheet.getRange(1,1,a.length, a[0].length).setValues(a);

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  let CostPerItem = ["Cost Per Item", 1, 2, 3, 4, 5];
  let a = => [e]);
  sh.getRange(1, 1, a.length, a[0].length).setValues(a);
Cost Per Item

Leave a ReplyCancel reply