[英]How to use range in google sheet api?
I want to add a new value from B3.我想从 B3 添加一个新值。
B1:E1 is from the first line of B to the first line of E. B1:E1 是从 B 的第一行到 E 的第一行。
B:E is from the beginning of B to the end of E. B:E 是从 B 的开头到 E 的结尾。
I wonder what the difference is when the range is B:E, B1:E1.我想知道当范围是 B:E、B1:E1 时有什么区别。
When there is a value in column A, the new value is appended to the end of A.当 A 列中有值时,新值会附加到 A 的末尾。
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append
service = discovery.build('sheets', 'v4', credentials=credentials)
spreadsheet_id = 'my-spreadsheet-id
range_ = 'sheet1!B:E' vs'sheet1!B1:E1' # Questions
value_input_option = ''
insert_data_option = ''
value_range_body = {
}
request = service.spreadsheets().values().append(spreadsheetId=spreadsheet_id, range=range_, valueInputOption=value_input_option, insertDataOption=insert_data_option, body=value_range_body)
response = request.execute()
pprint(response)
API will check if the provided range is part of a data table by checking the content of the adjacent cells. API 将通过检查相邻单元格的内容来检查提供的范围是否是数据表的一部分。 If both range and its adjacent cells contain data, the range is considered part of the data table.
如果范围及其相邻单元格都包含数据,则该范围被视为数据表的一部分。 (In your example, the data table is A1:E10 )
(在您的示例中,数据表是A1:E10 )
Since B:E and B1:E1 have data in cell B1 and B1 is adjacent to the data of cell A1 , the range is considered part of A1:E data table.由于B:E和B1:E1在单元格B1 中有数据并且B1与单元格A1的数据相邻,因此该范围被视为A1:E数据表的一部分。 This causes the API to append the data to column A.
这会导致 API 将数据附加到 A 列。
You can verify this by creating another sheet, populate only cells B1:E2 and execute the API.您可以通过创建另一个工作表来验证这一点,仅填充单元格B1:E2并执行 API。
Example:例子:
Here I used B:E as range在这里我使用B:E作为范围
Before Executing Append API:在执行 Append API 之前:
After Executing Append API执行 Append API 后
In your case, you need to explicitly define the row number in your range (B3:E3) and that range must be empty or else it will append its data to the first empty row below the provided range.在您的情况下,您需要明确定义范围 (B3:E3) 中的行号,并且该范围必须为空,否则它会将其数据附加到所提供范围下方的第一个空行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.