I try to format some cells to a date format in a google spreadsheet.
The data on the cell looks like this : 09/11/2021
And I try to make it looks like this : 11/2021
Or at least format the cell with a date format.
I use batchUpdate() to update cells :request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=body).execute()
What I tried :
- Both updateCells and repeatCell but none worked.
- Formatting before AND after adding the value to the cell.
- Change cells by changing rown or coln values (in the code below)
- Other date formats like
dd-mm-yyormm yyyy - Also read a lot of google documentation and watched their videos...
updateCells body
body = {
"requests": [
{
'updateCells': {
'range': {
'sheetId': sheet_id,
'startRowIndex': rown-1,
'endRowIndex': rown,
'startColumnIndex': coln,
'endColumnIndex': coln
},
'rows': {'values': [{'userEnteredFormat': {'numberFormat': {'type': "DATE", 'pattern': "mm/yyyy"}}}]},
'fields': 'userEnteredFormat.numberFormat'
}
}
]
}
repeatCell body
body = {
"requests": [
{
"repeatCell": {
"range": {
"sheetId": sheet_id,
"startRowIndex": rown-1,
"endRowIndex": rown,
"startColumnIndex": coln,
"endColumnIndex": coln
},
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "DATE",
"pattern": "mm/yyyy"
}
}
},
"fields": "userEnteredFormat.numberFormat"
}
}
]
}
Any tips and tricks or ideas are welcome !