我有一个python脚本,它必须将google工作表中的一列更新为特定的日期格式:
req = [
{
"repeatCell": {
"range": {
"sheetId": SHEET_ID,
"startColumnIndex": 2,
"endColumnIndex" : 3,
},
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "DATE",
"pattern": "dd-mmm-yyyy"
},
"horizontalAlignment" : "CENTER", #OPTIONS: 'LEFT', 'RIGHT', 'CENTER'
}
},
"fields": "userEnteredFormat(numberFormat,horizontalAlignment)",
}
}]
body = {'requests':req}
sheet.batchUpdate(spreadsheetId=SAMPLE_SPREADSHEET_ID, body=body).execute()
但是,更新不会通过。我检查了,据我所知,这是因为文件中的日期格式是string(以',比如'2021-03-06 14:19:17.102
开头)
我看到一些答案表明我必须将ValueInputOption
更改为“USER_ENTERED”,但我找不到在脚本中添加更改的位置?
例如:(How to format text as a number using the Google Sheets API?)
我尝试在最后一行添加ValueInputOption='USER_ENTERED'
,我尝试了body = {'requests':req, 'ValueInputOption':'USER_ENTERED'
。不确定这个更改应该放在哪里
或者是否有其他方法将“字符串”改写为日期和数字格式
说明:
ValueInputOption
参数来自不同的batchUpdate请求,即spreadsheets.values.batchUpdate
方法,不能在spreadsheets.batchUpdate
中使用此外,由于
'
的原因,单元格的值强制日期为字符串值,因此需要手动或通过spreadsheets.values.batchUpdate()
将其删除参考文献:
spreadsheets.batchUpdate()
spreadsheets.values.batchUpdate()
相关问题 更多 >
编程相关推荐