Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在何处添加ValueInput选项以启用日期格式设置?(谷歌网页API)_Python_Google Sheets Api - Fatal编程技术网

Python 在何处添加ValueInput选项以启用日期格式设置?(谷歌网页API)

Python 在何处添加ValueInput选项以启用日期格式设置?(谷歌网页API),python,google-sheets-api,Python,Google Sheets Api,我有一个python脚本,它必须将google工作表中的一列更新为特定的日期格式: req = [ { "repeatCell": { "range": { "sheetId": SHEET_ID, "startColumnIndex": 2,

我有一个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()
但是,更新不会通过。我检查了,据我所知,这是因为文件中的日期格式是字符串(以“,”开头,如
”2021-03-06 14:19:17.102

我看到一些答案表明我必须将
ValueInputOption
更改为“用户输入”,但我找不到在脚本中添加更改的位置?

例:()

我尝试在最后一行中添加
ValueInputOption='USER\u ENTERED'
,并尝试
body={'requests':req,'ValueInputOption':'USER\u ENTERED'
。不确定这项更改应该放在哪里


或者是否有其他方法将“字符串”覆盖为日期和数字格式?

说明:

ValueInputOption
参数来自不同的batchUpdate请求,即
spreadsheets.values.batchUpdate
方法,不能在
spreadsheets.batchUpdate
中使用

此外,由于
,单元格的值强制日期为字符串值,因此需要手动或通过
电子表格.values.batchUpdate()
将其删除

参考文献:


刚刚意识到“值输入”选项完全来自另一种方法,您正试图通过电子表格.batchUpdate来修改工作表的结构,而不是修改值。我编辑了关于这一问题的解释。