ves*_*abo 2 google-sheets python-3.x google-sheets-api google-colaboratory
我的代码如下
def write_cells(spreadsheet_id, update_data):
updating = sheet_service.spreadsheets().values().\
batchUpdate(spreadsheetId=spreadsheet_id, body=update_data)
updating.execute()
spreadsheet_data = [
{
"deleteDimension": {
"range": {
"sheetId": sheet_id,
"dimension": "ROWS",
"startIndex": 5,
"endIndex": 100
}
}
}
]
update_spreadsheet_data = {
'valueInputOption': 'USER_ENTERED',
'data': spreadsheet_data
}
update_data = update_spreadsheet_data
write_cells(spreadsheet_id, update_data)
Run Code Online (Sandbox Code Playgroud)
我有以下错误消息
HttpError Traceback (most recent call last)
<ipython-input-64-0ba8756b8e85> in <module>()
----> 1 write_cells(spreadsheet_id, update_data)
Run Code Online (Sandbox Code Playgroud)
2帧
/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in execute(self, http, num_retries)
838 callback(resp)
839 if resp.status >= 300:
--> 840 raise HttpError(resp, content, uri=self.uri)
841 return self.postproc(resp, content)
842
HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1lAI8gp29luZDKAS1m3P62sq0kKCn8eaMUvO_M_J8meU/values:batchUpdate?alt=json returned "Invalid JSON payload received. Unknown name "delete_dimension" at 'data[0]': Cannot find field.">
Run Code Online (Sandbox Code Playgroud)
我不明白这一点:“未知名称delete_dimension”。我无法解决它。如有任何帮助,我们将不胜感激,谢谢。
如果我的理解是正确的,那么这个修改怎么样?
spreadsheets().batchUpdate().spreadsheet_data是正确的。{"requests": spreadsheet_data}。def write_cells(spreadsheet_id, update_data):
# Modified
updating = sheet_service.spreadsheets().batchUpdate(
spreadsheetId=spreadsheet_id, body=update_data)
updating.execute()
spreadsheet_data = [
{
"deleteDimension": {
"range": {
"sheetId": sheet_id,
"dimension": "ROWS",
"startIndex": 5,
"endIndex": 100
}
}
}
]
update_spreadsheet_data = {"requests": spreadsheet_data} # Modified
update_data = update_spreadsheet_data
write_cells(spreadsheet_id, update_data)
Run Code Online (Sandbox Code Playgroud)
如果我误解了你的问题并且这不是你想要的结果,我很抱歉。
| 归档时间: |
|
| 查看次数: |
7796 次 |
| 最近记录: |