【发布时间】:2020-04-30 18:07:51
【问题描述】:
我需要使用 Google Sheets API v4(无 gspread)通过 Python 批量更新(使用空白信息)合并多个单元格。我有这个代码:
blank = setValue("") <----- I set a variable with no data to delete all the info that the cell can contains
dataBlank = [
...
{
'range': 'AB83',
'values': blank
}
{
'range': 'BH75:BH82', # <------- I think here is the problem
'values': blank
} ...
]
body = {
'valueInputOption': value_input_option,
'data': dataBlank
}
result = service.spreadsheets().values().batchUpdate(spreadsheetId=registro_id, body=body).execute()
print('{0} celdas borradas - Registro'.format(result.get('totalUpdatedCells')))
def setValue(value):
rvalue = [value]
avalue = [rvalue]
return avalue
它会运行,但在工作表中它只更新范围的第一个单元格,而整个范围不会更新。
我尝试使用'range' : 'BH75:BH82'、'range' : 'Sheet1!BH75:BH82',但无法更新整个范围。我需要使用批量更新,因为我需要检查性能并且不超过 Google Cloud 的报价限制。
我喜欢这个:
仅更新第一个单元格。如果我更新单个单元格或没有范围的合并单元格,它可以正常工作,但如果我使用范围更新则不起作用。
【问题讨论】:
标签: python google-sheets google-sheets-api