Advertisements
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)
shWorkspace.getRange(1,12,costPerItem.length,1).setValues(costPerItem);
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:
shProductData.getRange(1,1,fullDataArrayProducts.length,fullDataArrayProducts[0].length).setValues(fullDataArrayProducts)
To apply a 2d array and this works fine
>Solution :
Posting a flattened array as a column
let a = CostPerItem.map(e => [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 = CostPerItem.map(e => [e]);
sh.getRange(1, 1, a.length, a[0].length).setValues(a);
}
Cost Per Item |
---|
1 |
2 |
3 |
4 |
5 |