问题描述
我使用google-apis SDK进行开发.我可以使用sheets.spreadsheets.values.get
方法从工作表中获取值.但是它从该工作表返回整个值.我需要过滤类似查询的内容.
I used google-apis SDK for my development. I can able to get values from sheet by using sheets.spreadsheets.values.get
method. But it returns entire values from that sheet. I need to filter something like querying.
这是我真正尝试的,
假设上述数据为电子表格,在这里sheets.spreadsheets.values.get
将从该工作表返回整个值.但是我尝试通过[email protected]
Assume the above data as a spreadsheet, Here sheets.spreadsheets.values.get
this returns whole values from that sheet. But I try to do fetch first row by [email protected]
推荐答案
方法 spreadsheets.values.get 允许(并要求)指定范围
The method spreadsheets.values.get allows (and requires) you to specify a range
range
的样本值-为获取Sheet1的第5行将为Sheet1!A5:Z5
A sample value for range
- for getting row 5 of Sheet1 would be Sheet1!A5:Z5
更新
如果您不知道要检索哪一行,但想合并一个查询请求(例如在Google表格用户界面中),则可以:
If you do not know which row you want to retrieve, but want to incorporate a query request, such as in the Google Sheets UI:
无法使用Google Sheets API.
但是有一种解决方法:
使用Google 可视化API查询.
Use a Google Visualization API query.
工作流程:
- 将电子表格发布为具有链接的任何人都可以查看"
- 通过以下方式创建URL
- 获取电子表格的基本URL
https://docs.google.com/a/google.com/spreadsheets/d/XXXXXX
- 添加到URL
/gviz/tq?tq=
- 例如在表格用户界面中创建查询并对其进行URL编码
- 将URL编码的查询添加到您的URL
- Publish your spreadsheet as "Anyone with the link can view"
- Create the URL by
- taking the basic URL of your spreadsheet
https://docs.google.com/a/google.com/spreadsheets/d/XXXXXX
- add to the URL
/gviz/tq?tq=
- create you query such as in Sheets UI and URL encode it
- Add the URL encoded query to your URL
示例:
如果您的查询是
select A
,- URL将为
https://docs.google.com/spreadsheets/d/XXXXX/gviz/tq?tq=select%20A
- 并且GET请求的响应将是:
google.visualization.Query.setResponse({"version":"0.6","reqId":"0","status":"ok","sig":"1023816999","table":{"cols":[{"id":"A","label":"","type":"number","pattern":"General"}],"rows":[{"c":[{"v":1.0,"f":"1"}]},{"c":[{"v":4.0,"f":"4"}]}],"parsedNumHeaders":0}});
您可以根据需要访问嵌套的JSON结构,当然也可以根据需要制定查询条件.
You can access the nested JSON structure as desired and of course you can formulate your query as desired.
这篇关于如何使用Google-sheet-apis(Node.js)从Google-Sheet中提取特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- taking the basic URL of your spreadsheet
- 获取电子表格的基本URL