[英]Looking to update cells format to percent in gspread, receiving keyError
我希望將一列單元格更新為百分比,以便條件格式可以應用於它們。 當我運行以下命令時:
requests = [{
"repeatCell": {
"range": {
"sheetId": 0,
"startRowIndex": 3,
"endRowIndex": 27,
"startColumnIndex": 2,
"endColumnIndex": 3
},
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "PERCENT",
"pattern": "####.#"
}
}
},
"fields": "userEnteredFormat.numberFormat"
}
}]
res = wks.batch_update(requests)
print(res)
我得到了錯誤:
KeyError: 'range'
有誰知道怎么了? 感謝幫助。
答案: wks.batch_update(requests)
, wks 應該是sa.open
的結果,而不是特定的工作表(就像這里一樣)
請為您的用例找到以下代碼,它將滿足您的要求。
在您的代碼中,您缺少參數放置。
requests = {
"requests": [
{
"repeatCell": {
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "PERCENT",
"pattern": "0.00%"
}
}
},
"range": {
"sheetId": w23._properties['sheetId'],
"startRowIndex": 3,
"endRowIndex": 27,
"startColumnIndex": 2,
"endColumnIndex": 3,
},
"fields": "userEnteredFormat.numberFormat"
}
}
]
}
response=sh.batch_update(body=requests)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.