我正在使用google-client-api-python v4并尝试使用以下代码更新工作表的属性
for sheet in result.get('sheets', ''):
sheetId = (sheet.get("properties", {}).get("sheetId", 0))
batch_request = {
"requests": [
{
"UpdateSheetProperties": {
"properties": {
"sheetId": sheetId,
"gridProperties": {
"rowCount": 2000,
"columnCount": 4,
}
}
}
}
],
}
result = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=batch_request).execute()
当我运行脚本时,我收到以下错误
json返回“收到无效的JSON有效负载。未知名称 'updates [0]'处的“update_sheet_properties”:找不到字段。“
我做错了什么?
答案 0 :(得分:1)
我发现了错误
首先应该是
"updateSheetProperties": {
而不是
"UpdateSheetProperties": {
我还需要以下一行
"fields" : "gridProperties(rowCount, columnCount)"
实际代码是
for sheet in result.get('sheets', ''):
sheetId = (sheet.get("properties", {}).get("sheetId", 0))
batch_request = {
"requests": [
{
"updateSheetProperties": {
"properties": {
"sheetId": sheetId,
"gridProperties": {
"rowCount": 2000,
"columnCount": 4,
}
},
"fields" : "gridProperties(rowCount, columnCount)"
}
}
],
}
result = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=batch_request).execute()
杰