指定有效的“范围".用于批处理值请求 [英] Specifying valid "ranges" for batch values requests
问题描述
我正在使用适用于Python的Google Sheets API快速入门.我试图从Google表格api一次提取多个单元格,一次只提取一个单元格,然后将每个值插入文本文档中.我一直在使用spreadsheets().values().get()
进行此操作,但是我使用API的次数过多,并且batchGet()
方法似乎会更好.我通读了Google Sheets API v4,但找不到spreadsheets().values().batchGet()
上ranges
参数的正确格式.根据文档,看起来它需要一个字符串数组,或者可能是一个JSON对象,但是文档中没有格式的示例(实际上,它表示// TODO
!).有人知道正确的格式吗?我已经尝试过:
I'm using the Google Sheets API quickstart for Python. I'm trying to pull multiple cells, just one cell at a time, from the google sheets api and plug each value into a text document. I've been doing this with spreadsheets().values().get()
, but I'm hitting the API too much and the batchGet()
method seems like it would be better. I read through the Google Sheets API v4 but was unable to find the correct formatting for the ranges
parameter on spreadsheets().values().batchGet()
. According to the docs, it appears that it takes an array of strings, or possibly a JSON object, but there's no example of the format in the docs (In fact, it says // TODO
!). Does anyone know the correct format? I've tried:
spreadsheetId = 098217340987123049817235blahblahblah
ranges = ["A100:A100, "B100:B100"]
spreadsheets().values().batchGet(spreadsheetId=spreadsheetId, ranges=ranges)
和
spreadsheetId = 098217340987123049817235blahblahblah
ranges = ["A100:A100"]
spreadsheets().values().batchGet(spreadsheetId=spreadsheetId, ranges=ranges)
还有一个确定的字符串
spreadsheetId = 098217340987123049817235blahblahblah
ranges = "A100:A100"
spreadsheets().values().batchGet(spreadsheetId=spreadsheetId, ranges=ranges)
每个返回[]
.
当我使用spreadsheets().values().get()
和ranges="A100:A100
时,函数返回[['cellvalue']]
,所以我知道那里有数据.
When I use spreadsheets().values().get()
and ranges="A100:A100
, function returns [['cellvalue']]
, so I know there's data there.
有什么想法吗?
推荐答案
您可以签入链接使用batchGet
的示例代码.
You may check in this link the sample code in using batchGet
.
spreadsheetId = '1SizdeufKaODnq3WMV3T3uS2W47v4mZJeqYg2J1MiP9k'
rangeName = 'Sheet1!A2:A'
result = service.spreadsheets().values().get(spreadsheetId=spreadsheetId, range=rangeName).execute()
由于ranges
是值的 A1标记要进行检索,这是一个类似于Sheet1!A1:B2
的字符串,它引用电子表格中的一组单元格,通常在公式中使用.
Since ranges
is the A1 notation of the values to retrieve, this is a string like Sheet1!A1:B2
that refers to a group of cells in the spreadsheet, and is typically used in formulas.
例如,有效范围是:
-
Sheet1!A1:B2
指的是Sheet1的前两行中的前两个单元格. -
Sheet1!A:A
引用Sheet1第一列中的所有单元格. -
Sheet1!1:2
是指Sheet1的前两行中的所有单元格. -
Sheet1!A5:A
是指工作表1第一列(从第5行开始)的所有单元格. -
A1:B2
指的是第一个可见工作表的前两行中的前两个单元格. -
Sheet1
引用Sheet1中的所有单元格.
Sheet1!A1:B2
refers to the first two cells in the top two rows of Sheet1.Sheet1!A:A
refers to all the cells in the first column of Sheet1.Sheet1!1:2
refers to the all the cells in the first two rows of Sheet1.Sheet1!A5:A
refers to all the cells of the first column of Sheet 1, from row 5 onward.A1:B2
refers to the first two cells in the top two rows of the first visible sheet.Sheet1
refers to all the cells in Sheet1.
还支持命名范围.当命名范围与工作表的名称冲突时,首选命名范围.
Named ranges are also supported. When a named range conflicts with a sheet's name, the named range is preferred.
如果工作表名称包含空格或以方括号开头,请用单引号('
)包围工作表名称,例如'Sheet One'!A1:B2
.为简单起见,将工作表名称始终用单引号引起来是安全的.
If the sheet name has spaces or starts with a bracket, surround the sheet name with single quotes ('
), e.g 'Sheet One'!A1:B2
. For simplicity, it is safe to always surround the sheet name with single quotes.
这篇关于指定有效的“范围".用于批处理值请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!