谷歌工作表API Python Clear sh

2024-10-01 05:01:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想不断更新/重新写入谷歌工作表。但是,如果不清除旧工作表,我就不能只更新它,因为有时更新的行数少于表中保留的前一行和旧行。在

因此,developer page上列出的协议是:

{
  "requests": [
    {
      "updateCells": {
        "range": {
          "sheetId": sheetId
        },
        "fields": "userEnteredValue"
      }
    }
  ]
}

翻译成python应该是这样的,我想:

^{pr2}$

返回错误:

在GoogleAppClient.errors.HttpError: https://sheets.googleapis.com/v4/spreadsheets/[独一无二]/值:batchUpdate?alt=json returned“接收到无效的json负载。未知名称“requests”:找不到字段。“>

奇怪的是“请求”是无效的,因为它列在协议中。不管怎样,还有人能用这个吗?谢谢。-杰森


Tags: json协议developerfields错误pagerangerequests
2条回答
result = service.spreadsheets( ).values( ).batchUpdate(...

应该是:

^{pr2}$

我花了很长时间才注意到代码中的相同错误。。。在

找到一个不同的method

rangeAll = '{0}!A1:Z'.format( sheetName )
body = {}
resultClear = service.spreadsheets( ).values( ).clear( spreadsheetId=spreadsheet_id, range=rangeAll,
                                                       body=body ).execute( )

这个很好用。还在想为什么请求updateCells协议不起作用。在

相关问题 更多 >