如何使用 Google Sheets API v4 处理用于检索行的结构化查询
How to handle structured queries for retrieving rows with Google Sheets API v4
我想开始将依赖于 Google Spreadsheet API (v3) 的应用程序迁移到 Google Sheets API v4。但是,在开始之前我还有一个问题。
在 Google Sheets API v3 中,我可以使用请求 URL 中的 sq
参数通过结构化查询获取基于行的提要。如果 sheet 有 10000 行并且我只需要在特定列中获取具有特定值的行,这将很有用。它在速度方面也非常高效。
在查看 Google 的 v4 迁移指南时,我在 "Retrieve Row Data" 下找到了这条语句:
The Sheets API v4 does not currently have a direct equivalent for the Sheets
API v3 structured queries. However, you can retrieve the relevant data and
sort through it as needed in your application.
鉴于 v4 API 中没有结构化查询,我如何从 10000 行的 sheet 中高效地检索 "relevant data"。我宁愿不必检索所有 10000 行来筛选该响应。特别是因为它会减慢我的应用程序速度并可能增加通过网络发送的数据量。
使用 v4 API,我如何检索在特定列(或一组列)中具有特定值的行?
我不需要参考文档,因为你已经知道了。 Sheetsv4 中没有这样的功能。您必须手动执行 Basic Reading methods 并解析响应,遍历它并筛选您要查找的值。
这与您的SO question here有关。我已经在那里写了一些代码,所以我将 post 这里的结果,以便您了解我如何搜索值。
为了获取 phone
,我遍历了 JSON 响应:
arrayBuffer = xhr.response;
console.log("arrayBuffer "+ arrayBuffer);
myArr = JSON.parse(arrayBuffer);
for(var i = 0; i < myArr.values.length; i++){
if(myArr.values[0][i] === "phone"){
console.log("column position is " + (i+1)); // +1 because counting starts at 0
}
}
您还可以提交 Feature Request here.
我想开始将依赖于 Google Spreadsheet API (v3) 的应用程序迁移到 Google Sheets API v4。但是,在开始之前我还有一个问题。
在 Google Sheets API v3 中,我可以使用请求 URL 中的 sq
参数通过结构化查询获取基于行的提要。如果 sheet 有 10000 行并且我只需要在特定列中获取具有特定值的行,这将很有用。它在速度方面也非常高效。
在查看 Google 的 v4 迁移指南时,我在 "Retrieve Row Data" 下找到了这条语句:
The Sheets API v4 does not currently have a direct equivalent for the Sheets
API v3 structured queries. However, you can retrieve the relevant data and
sort through it as needed in your application.
鉴于 v4 API 中没有结构化查询,我如何从 10000 行的 sheet 中高效地检索 "relevant data"。我宁愿不必检索所有 10000 行来筛选该响应。特别是因为它会减慢我的应用程序速度并可能增加通过网络发送的数据量。
使用 v4 API,我如何检索在特定列(或一组列)中具有特定值的行?
我不需要参考文档,因为你已经知道了。 Sheetsv4 中没有这样的功能。您必须手动执行 Basic Reading methods 并解析响应,遍历它并筛选您要查找的值。
这与您的SO question here有关。我已经在那里写了一些代码,所以我将 post 这里的结果,以便您了解我如何搜索值。
为了获取 phone
,我遍历了 JSON 响应:
arrayBuffer = xhr.response;
console.log("arrayBuffer "+ arrayBuffer);
myArr = JSON.parse(arrayBuffer);
for(var i = 0; i < myArr.values.length; i++){
if(myArr.values[0][i] === "phone"){
console.log("column position is " + (i+1)); // +1 because counting starts at 0
}
}
您还可以提交 Feature Request here.