Google sheets 使用google sheets API一次修改同一行中的多个单元格
我正在使用Google Sheets API BatchUpdate()端点修改给定电子表格中特定单元格的背景色 现在的问题是,我发送的请求只更新一个单元格,而我无法找到一个解决方案来一次性更新整行(我的工作表中每行大约有22个单元格) 我使用的请求主体是:Google sheets 使用google sheets API一次修改同一行中的多个单元格,google-sheets,google-api,google-sheets-api,spreadsheet,Google Sheets,Google Api,Google Sheets Api,Spreadsheet,我正在使用Google Sheets API BatchUpdate()端点修改给定电子表格中特定单元格的背景色 现在的问题是,我发送的请求只更新一个单元格,而我无法找到一个解决方案来一次性更新整行(我的工作表中每行大约有22个单元格) 我使用的请求主体是: request = [{ "updateCells": { "range": { "sheetId": sheet_id,
request = [{
"updateCells": {
"range": {
"sheetId": sheet_id,
"startRowIndex": 20,
"endRowIndex": 21,
"startColumnIndex": 1,
"endColumnIndex": 8
},
"rows": [
{
"values": [{
"userEnteredFormat": {
"backgroundColor": {
"red": 1,
"green": 1,
"blue": 0,
"alpha": 1.0, # this parameter is not working properly in the API
}}}
]
}
],
"fields": 'userEnteredFormat.backgroundColor',
}}]
行和列参数中显示的值有点任意,因为对其进行了一些测试
包含请求的Python代码:
response = service.spreadsheets().batchUpdate(spreadsheetId=SPREADSHEET_ID, body=body).execute()
这里的问题是,Google Sheets API限制了用户能够发出的请求量,因此可能需要大约3分钟的过程需要3小时
关于如何更新请求主体有什么想法吗?也许我错过了什么。我相信你的目标和情况如下
- 要修改行中单元格的背景色。
- 从脚本中,您希望将“B”列中的单元格修改到工作表列的末尾
- 您希望通过使用googleapis和python来实现这一点
- 您已经能够使用Sheets API获取和输入Google电子表格的值
- 在这种情况下,当未使用
时,背景色将从endColumnIndex
的单元格修改到工作表上的列末尾startColumnIndex
- 当使用
“endColumnIndex”:8时,列“B”到“H”的背景色将被修改
request = [{
"repeatCell": {
"range": {
"sheetId": sheet_id,
"startRowIndex": 20,
"endRowIndex": 21,
"startColumnIndex": 1,
# "endColumnIndex": 8
},
"cell": {
"userEnteredFormat": {
"backgroundColor": {
"red": 1,
"green": 1,
"blue": 0,
"alpha": 1.0,
}}},
"fields": 'userEnteredFormat.backgroundColor',
}}]