I would like to create a table in a google sheet with different type of data : title/string (in A1 : "Clients Indépendants") > string ("A2" : "Montant") > number ("B2" : '43766468' linked to a variable)/ "A5" : an empty cell. Example:
I can create a new sheet and my variable which contains a filter and a formula works. However I don’t succeed to add different type of data in the same sheet. Here the body request :
request_body6 = {
"requests" : [
{
"updateCells": {
"rows" : {
"values" : [
{
"userEnteredValue" :
{
"stringValue": 'Clients indépendant',
"stringValue": 'Montant',
"numberValue": montant_total_independants,
"stringValue": 'Nb clients',
"numberValue": nombre_client_independants,
}
}
]
},
"start" : {
"sheetId" : id_new_sheet6,
"rowIndex" : 0,
"columnIndex" : 0
},
"fields" : "userEnteredValue"
}
}
]
}
Here the error :
'description': "Invalid value at 'requests[0].update_cells.rows.values[0].user_entered_value' (oneof), oneof field 'value' is already set. Cannot set 'numberValue'"}]}]">
Do you have any ideas how to proceed ?
CodePudding user response:
Your code throws an error because you are trying to pass multiple entries into a single cell. userEnteredValue
should only hold one value, the others being other elements of the values
list. Assuming you want to populate A1
, A2
and B2
, schematically your request object should look like this:
{"rows" : [{"values":[{A1}, {A2}]}, {"values": [{},{B2}]}]}
And in your specific case:
"rows" : [
{"values":[
{"userEnteredValue":{"stringValue": 'Clients indépendant'}},
{"userEnteredValue":{"stringValue": 'Montant'}},
]},
{"values":[
{},
{"userEnteredValue":{"numberValue": montant_total_independants}},
]}
]
You can find the relevant documentation on how to structure such requests here.