Reputation: 9479
I've seen the following SO quesiton and I thought my array was 2d. Here's my code:
var testingArray = [
{ poolIndex: 0 },
{ stakingStrategy: 'masterchef' },
{ farmName: 'sushiChef' }
];
function placeSushiData () {
let ss = SpreadsheetApp.getActiveSpreadsheet();
let targetSheet = ss.getSheetByName('test spreadsheet');
let targetRange = targetSheet.getRange(11,2, 2, testingArray.length)
targetRange.setValues(testingArray)
}
But I'm still getting this error:
Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues.
Why isn't my array 2d? If it isn't, how do I make it 2D? Or, more broadly, how do I get it into two rows of my google sheet?
Upvotes: 0
Views: 47
Reputation: 7012
A 2d array is a matrix. basically, it's an array of arrays of values.
So, your data should look something like this:
const testingArray = [
[ "2.000", "1,000,000", "$2.99" ],
[ "stakingStrategy", "masterchef", '' ],
[ "farmName", "sushiChef", '' ]
];
Here's an example from the official documentation.
Upvotes: 2
Reputation: 64042
function placeSushiData () {
var A = [["poolIndex", 0 ],["stakingStrategy",'masterchef'],[ "farmName", 'sushiChef' ]];
let ss = SpreadsheetApp.getActive();
let sh = ss.getSheetByName('Sheet2');
let rg = sh.getRange(11,2, A.length, A[0].length)
rg.setValues(A)
}
Output:
poolIndex | 0 | |
stakingStrategy | masterchef | |
farmName | sushiChef | |
Upvotes: 4