Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python google sheets api选择非相邻单元格_Python_Google Sheets_Google Spreadsheet Api - Fatal编程技术网

Python google sheets api选择非相邻单元格

Python google sheets api选择非相邻单元格,python,google-sheets,google-spreadsheet-api,Python,Google Sheets,Google Spreadsheet Api,选择多个非相邻单元的范围是多少 我正在尝试更新工作表A2和A5中不相邻的单元格。我知道如何更新连续单元格:“SheetName”!A2:5,但如何仅更新单元格2和5。我正在使用python: sheetRange = str("'Telegram'!A2:5") value_range = [['a'],['False'],['True']] value_range = { "values": value_range, } request

选择多个非相邻单元的范围是多少

我正在尝试更新工作表A2和A5中不相邻的单元格。我知道如何更新连续单元格:“SheetName”!A2:5,但如何仅更新单元格2和5。我正在使用python:

    sheetRange = str("'Telegram'!A2:5")
    value_range = [['a'],['False'],['True']]
    value_range = {
        "values": value_range,
    }
    request = self.service.spreadsheets().values().update(spreadsheetId=self.spreadsheetid, range=sheetRange,
                                                          valueInputOption="RAW",
                                                          body=value_range )
    response = self.requestExecute(request)
    return response

使用sheets.spreadsheets.batchUpdate怎么样?通过使用sheets.spreadsheets.batchUpdate,您可以更新每个单元格,如A2和A5。下面的示例脚本来自。您可以从该脚本中看到请求正文

请注意,在这种情况下,用于单元格坐标的不是

示例脚本: 此示例脚本假定您已经准备好使用API v4

batch_update_spreadsheet_request_body = {
    "requests":
    [
        {
            "updateCells":
            {
                "range":
                {
                    "sheetId": #####, # Please input your sheetId.
                    "startRowIndex": 1,
                    "endRowIndex": 2,
                    "startColumnIndex": 0,
                    "endColumnIndex": 1
                },
                "rows":
                [
                    {
                        "values":
                        [
                            {
                                "userEnteredValue":
                                {
                                    "stringValue": "sample value for A2"
                                }
                            }
                        ]
                    }
                ],
                "fields": "*"
            }
        },
        {
            "updateCells":
            {
                "range":
                {
                    "sheetId": #####,  # Please input your sheetId.
                    "startRowIndex": 4,
                    "endRowIndex": 5,
                    "startColumnIndex": 0,
                    "endColumnIndex": 1
                },
                "rows":
                [
                    {
                        "values":
                        [
                            {
                                "userEnteredValue":
                                {
                                    "stringValue": "sample value for A5"
                                }
                            }
                        ]
                    }
                ],
                "fields": "*"
            }
        }
    ]
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=batch_update_spreadsheet_request_body)
response = request.execute()
print(response)
参考: sheets.spreadsheets.batchUpdate的详细信息为。您还可以在这里看到示例脚本。 网格范围: a1表示法:
如果我误解了你的问题,很抱歉。

我的答案有用吗?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。