how can i update multiple cells value at one time? suppose i want to update cells A5,C5 and F5 all together. i have done something like this.but it doesn’t work.*******
`
$.ajax({
type: 'put',
headers: { Authorization: auth, 'content-type': 'application/json' },
data: JSON.stringify(
{
"range": "users!A5",
"values": [["abc"]]
},
{
"range": "users!C5",
"values": [["abc2"]]
},{
"range": "users!F5",
"values": [["ab"]]
}
),
url: 'https://sheets.googleapis.com/v4/spreadsheets/' + sheetId + '?valueInputOption=RAW',
success: function (r) {
console.log(r)
}, error: function (r) {
console.log(r)
}
})
`
2
Answers
I made some test, I use the following to make the updates in multiple cells.
I change the type from:
to:
I also change the request from:
to:
Note: the worksheet-id mentioned in the range can be found in the URL of the Google Sheet, like this:
Or getting the sheet properties. Keep in mind that the worksheet-id is 0 if you are working with “Sheet1,” and is not required to add it in that scenario.
Lastly, I change the URL from:
to:
In this case, "Method: spreadsheets.values.batchUpdate" can be used.
In your showing script, it is required to modify the endpoint and the method, and the request body. When these are reflected in your script, it becomes as follows.
In your script, the spreadsheet ID is used as the variable name of
sheetId
. Although I’m not sure about your actual situation, I’m worried about it. In this case, please use the spreadsheet ID instead of the sheet ID. Please be careful about this.Modified script:
Reference: