So, it is really a follow-up question based on my last attempt
So, I thought to use batchUpdate
command to do the following in a single API call
- Add a new column.
- Give a name to the column at
A1:A2
(usingA1 notation
) - Provide the formatting for the column values
A2:A
(for all the values that will fall into this column.
I structured my API call and executed as following
curl -v \
-H 'Authorization: Bearer ya29.GlxUB-UnpiYLeMzdAYyz_kVvNIVwmlMvxauAfiklslphd60INbgOQEr2eUwdx4smOSirde63hW2CvR17AMfj1P5iGw1Q3dRgGBHGZ92JKoFWozSxjbJh0wEZJKvDUQ' \
-H 'Content-Type: application/json' \
-d '{
"requests": [
{
"insertDimension": {
"range": {
"sheetId": 2052094881,
"dimension": "COLUMNS",
"startIndex": 0,
"endIndex": 1
}
}
},
{
"repeatCell": {
"range": {
"sheetId": 2052094881,
"startRowIndex": 0,
"endRowIndex": 1,
"startColumnIndex": 0,
"endColumnIndex": 1
},
"cell": {
"userEnteredValue": {
"stringValue": "discretionary"
}
},
"fields": "userEnteredValue.stringValue"
}
},{
"repeatCell": {
"range": {
"sheetId": 2052094881,
"startRowIndex": 1,
"startColumnIndex": 1,
},
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "DATE_TIME",
"pattern": "dddd, m/d/yy at h:mm"
}
}
},
"fields": "userEnteredFormat.numberFormat"
}
},
],
}' \
https://sheets.googleapis.com/v4/spreadsheets/1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8:batchUpdate
This seemed to work fine as I could see a new Column at index 0
which is A
and the API response was also good
< HTTP/2 200
< content-type: application/json; charset=UTF-8
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< date: Mon, 29 Jul 2019 20:09:29 GMT
< server: ESF
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< alt-svc: quic=":443"; ma=2592000; v="46,43,39"
< accept-ranges: none
<
{
"spreadsheetId": "1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8",
"replies": [
{},
{},
{}
]
}
* Connection #0 to host sheets.googleapis.com left intact
So, I thought to verify that if now I put any value into this column (starting from A2
), the formatting dddd, m/d/yy at h:mm
would be applied. So I inserted a value which looks like following command
curl -v \
-H 'Authorization: Bearer ya29.GlxUB3ad1mGpbFBT1raZx2C76kmiSPBDX6_epAWNd3hwWC7EMtzgVBPB34JAK543N7g2Y1cYeFc_VWjTpmeU7LSE4nDGiyCUafqhqPTJHUg5UmrfjVxH5pcmeJXK4Q' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"valueInputOption": "USER_ENTERED",
"data": [
{
"range": "Sheet1!A2:A3",
"majorDimension": "COLUMNS",
"values": [
["7/29/2019 12:56:31"]
]
}
]
}' \
https://sheets.googleapis.com/v4/spreadsheets/1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8/values:batchUpdate
When I executed, the response seemed fine
< HTTP/2 200
< content-type: application/json; charset=UTF-8
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< date: Mon, 29 Jul 2019 20:09:58 GMT
< server: ESF
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< alt-svc: quic=":443"; ma=2592000; v="46,43,39"
< accept-ranges: none
<
{
"spreadsheetId": "1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8",
"totalUpdatedRows": 1,
"totalUpdatedColumns": 1,
"totalUpdatedCells": 1,
"totalUpdatedSheets": 1,
"responses": [
{
"spreadsheetId": "1mHrPXQILuprO4NdqTgrVKlGazvvzgCFqIphGdsmptD8",
"updatedRange": "Sheet1!A2",
"updatedRows": 1,
"updatedColumns": 1,
"updatedCells": 1
}
]
}
However, when I looked at the Sheet from the browser, the literal value 7/29/2019 12:56:31
was available. I found this incorrect, because I expected formatting dddd, m/d/yy at h:mm
to have applied
I am looking to find out the answers to the following questions
- First, what am I doing wrong here?
- How do I fix this issue?
- How can I know the formatting of a column when looking at the column using the browser view?
Thank you very much for reading this far!