I'm trying to write a map(key, value) pair to google sheets using app script. I have tried using the method below
var crNew = SpreadsheetApp.create("newWorksheetName",1,1);
var ssNew = SpreadsheetApp.openByUrl(crNew.getUrl());
var x=ssNew.getRange("A1");
x.setValues(apimap.keys,apimap.values);
but I'm getting an error as follows
Exception: The parameters (String,String) don't match the method signature for SpreadsheetApp.Range.setValues. myfunction @ Code.gs:102
Can anyone please tell that where i'm doing wrong.The line 102 is this one x.setValues(apimap.keys,apimap.values);
CodePudding user response:
You are trying to call setValues
method with 2 arguments.
CodePudding user response:
I have acheived my task as follow and posting here if someone faces it in future.
var crNew = SpreadsheetApp.create("newWorksheetName",1,1);
var ssNew = SpreadsheetApp.openByUrl(crNew.getUrl());
var a=[];
apimap.forEach (function(value, key) { //apimap is my map containing data
a.push([key,value]); //i pushed data map into an array
})
var x=ssNew.getSheetByName("Sheet1").getRange(1,1,a.length,a[0].length);
x.setValues(a);
This automatically writes keys in one column and values in the adjacent column