根据列中的值过滤Google表格

时间:2018-04-04 13:05:11

标签: javascript node.js google-sheets google-sheets-api google-api-nodejs-client

我需要使用Sheets API阅读Google表格。我可以获取所有行,但是由于这些行数以万计并且将继续增长,我需要找到一种方法来过滤它们而不需要获取所有行。

我只需要一个SQL WHERE子句,其中包含一个或多个列的相等条件。例如,有一个phoneNumber列,它是工作表中的C列。我只需要获取此列的值等于某个值的行。

我目前正在使用Google Sheets V4 API for Node.js。我使用的是get api,但由于它只有#include <unordered_set> struct Foo { int set_value; int other_value; }; struct SetEqual { bool operator()(Foo * lhs, Foo * rhs) const noexcept { return lhs->set_value == rhs->set_value; } }; struct SetHasher { size_t operator()(Foo * foo) const noexcept { std::hash<int> hasher; return hasher(foo->set_value); } }; std::unordered_set<Foo *, SetHasher, SetEqual> my_set; void replace_if_lower(Foo * foo) { auto insertion_result = my_set.insert(foo); bool was_inserted = insertion_result.second; auto insertion_it = insertion_result.first; if (!was_inserted) { // Replace iff the other value is lower if (foo->other_value < (*insertion_it)->other_value) { // This is what I would like to do: // *insertion_it = foo; // This is the best I could figure out: my_set.erase(insertion_it); my_set.insert(foo); } } } 作为唯一可用的过滤器选项,我想到尝试getByDataFilter api假设它提供了一些过滤数据的方法。

不幸的是,range API中唯一的好方法是在GridRange中使用DataFilter。除了使用行和/或列范围外,这仍然不允许我提供过滤数据的任何条件。

那么有没有办法在不获取所有行的情况下执行此操作?我不能修改那个特定的表格。我现在能找到的唯一方法是在午夜运行一个cron作业,将数据与数据库同步,然后查询数据库。
有没有更好的方法来过滤数据?

1 个答案:

答案 0 :(得分:0)

您可以直接在网址上使用Google可视化查询:

如果你的网址是

docs.google.com/spreadsheets/d/id

你想要Select A,sum(B) group by A, 使用:

docs.google.com/spreadsheets/d/id/gviz/tq?tq="your encoded query here"  
https://docs.google.com/spreadsheets/d/1r8_mfnZAvTFmT02JHi1XgOwn_-sLCR9XgmR8wEQ4uW4/gviz/tq?tq=select%A%2C%20sum(B)%20group%20by%20A