简体   繁体   English

如何在google sheet api中使用范围?

[英]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:EB1: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) 中的行号,并且该范围必须为空,否则它会将其数据附加到所提供范围下方的第一个空行。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 google 的电子表格 API 来检索创建电子表格的日期和时间? - How can I use google's spreadsheet API to retrieve the date and time a spread sheet is created? 使用相同的credentials.json 在python 中访问google drive/google sheet api - use the same credentials.json to access google drive/google sheet api in python 从熊猫添加数据时如何为谷歌工作表动态设置“范围” - How to set dynamically "range" for google sheet when add data from panda Pandas Google 表格 API - append 数据帧 - Pandas Google sheet API - append data frames 如何在 Google Colab 中使用 OpenPose Python API? - How to use the OpenPose Python API in Google Colab? 截取 Google 表格中的某个范围或 Python 中的 Excel 的屏幕截图? - Take screen shot of a range in Google Sheet or Excel in Python? 如何通过Python使用SHEET API v4删除Google电子表格中的行? - How to delete rows in google spreadsheet using SHEET API v4 by Python? 如何将 google-api-client 用于 Google Cloud Logging - How to use google-api-client for Google Cloud Logging Python-Google Sheets API-未写入指定范围 - Python - Google Sheets API - Not Writing to the Specified Range 使用谷歌表 API V4 中的 python 将特定单元格格式化为最新 - Format specific cell to date with python in google sheet API V4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM