'Google Sheets API v4 Values.update syntax
Cannot get the right/correct syntax for Values.update, there is no examples of code for Google Apps Script on Google documentation. Tried to use the code pattern from batchUpdate limiting the range to one but it is not working. Could anyone please advise the correct syntax for Values.update? Here is the code:
function updateOneCell() {
var spreadsheetId = "someSpreadsheetId";
var request = {
"valueInputOption": "USER_ENTERED",
"data": [
{
"range": "Sheet1!BW7",
"majorDimension": "ROWS",
"values": [[new Date()]]
}
]
};
Sheets.Spreadsheets.Values.update(request, spreadsheetId);
}
It is giving the following error:
Invalid number of arguments provided. Expected 3-4 only
Thank you.
Solution 1:[1]
How about this modification?
Modification points :
1. About errorInvalid number of arguments provided. Expected 3-4 only
This means that for Sheets of Advanced Google Services, Sheets.Spreadsheets.Values.update() has 3 or 4 arguments as follows.
Sheets.Spreadsheets.Values.update(resource, spreadsheetId, range)Sheets.Spreadsheets.Values.update(resource, spreadsheetId, range, optionalArgs)
Range of BW7 cannot be used. Because the following error occurs.
Range ('Sheet1'!BW7) exceeds grid limits. Max rows: 1000, max columns: 26
The modified script reflected those is as follows.
Modified script :
function updateOneCell() {
var spreadsheetId = "someSpreadsheetId";
var request = {
majorDimension: "ROWS",
values: [[new Date()]]
};
Sheets.Spreadsheets.Values.update(
request,
spreadsheetId,
"Sheet1!A1",
{valueInputOption: "USER_ENTERED"}
);
}
If I misunderstand your question, I'm sorry.
Solution 2:[2]
worked for me:
sheets.spreadsheets.values.update(
{
spreadsheetId,
range: 'Sheet1!B3:C4',
valueInputOption:'RAW',
resource: {
values: [
['B3', new Date()],
['C3', 'C4']
],
}
}
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanaike |
| Solution 2 | alex_1948511 |
