[英]Looking to update cells format to percent in gspread, receiving keyError
I'm looking to update a column of cells to percentages, so conditional formatting can apply to them.我希望将一列单元格更新为百分比,以便条件格式可以应用于它们。 When I run the following:当我运行以下命令时:
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)
I'm given the error:我得到了错误:
KeyError: 'range'
Does anyone know what's wrong?有谁知道怎么了? Appreciate the help.感谢帮助。
Answer: wks.batch_update(requests)
, wks should be the result of sa.open
, not the specific worksheet (as it was here)答案: wks.batch_update(requests)
, wks 应该是sa.open
的结果,而不是特定的工作表(就像这里一样)
Please find the following code for your use case it will fix your requirements.请为您的用例找到以下代码,它将满足您的要求。
in your code, you are missing parameter placement.在您的代码中,您缺少参数放置。
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.