Select 具有查询的特定列中的特定行和行范围
Select specific row and range of rows from specific columns with query
我有以下价差sheet:
| | A | B | C | D | E |
| 1| Labels | Item 1 | Item 2 | Item 3 | Item 4 |
| 2| name | yes | no | yes | yes |
| 3| price | yes | no | yes | yes |
| 4| tag | yes | no | yes | yes |
| 5| desc | yes | no | yes | yes |
| 6| loc | yes | no | yes | yes |
| 7| ref | yes | no | yes | yes |
| 8| obj | yes | no | yes | yes |
| 9| rand | yes | no | yes | yes |
|10| rand2 | yes | no | yes | yes |
|11| rand3 | yes | no | yes | yes |
|12| rand4 | yes | no | yes | yes |
注:1到12和A到E不在sheet
范围内
如何 select 第 1 行和第 5 行到第 10 行的范围 A
、C
、E
得到以下结果? :
| | A | C | E |
| 1| Labels | Item 2 | Item 4 |
| 5| desc | no | yes |
| 6| loc | no | yes |
| 7| ref | no | yes |
| 8| obj | no | yes |
| 9| rand | no | yes |
|10| rand2 | no | yes |
注意:我留下了 1、5、6、...、10 和 A、C、E 只是为了更好地理解输出。我不希望它们出现在我的数据中,我只想要 sheet
中的数据
我得到了类似这样的行范围的东西:SELECT A,C,E LIMIT 6 OFFSET 4
但是我错过了第 1 行并且找不到如何在同一个查询中添加它。
尝试:
=QUERY(A1:E; "select A,C,E limit 6 offset 3"; 1)
如果您正在寻找使用 Google 脚本的解决方案:
如果要考虑的范围将由用户手动选择,您可能有兴趣使用 getActiveRangeList()
文档:https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getactiverangelist
如果要考虑的范围是固定的并且可以集成到您的脚本中,您可能会对使用 getRangeList()
感兴趣
文档:https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getrangelista1notations
请注意,如果您想在脚本中迭代 rangeList,您还需要使用 getRanges()
检索列表的不同范围。
示例:
var rangeList = ss.getActiveRangeList();
var myRanges = rangeList.getRanges();
for (i = 0; i < myRanges.length; i++) {
...
}
希望对您有所帮助。
干杯
有查询:
=query(filter({row(A1:A),A1:E&""},A1:A<>""), "Select Col2, Col4, Col6 where Col1=1 or Col1>=5 and Col1<=10")
带过滤器:
=filter({A1:A & "",C1:C&"", E1:E& ""},((row(A1:A)=1)+(row(A1:A)>=5)*(row(A1:A)<=10))>0)
我有以下价差sheet:
| | A | B | C | D | E |
| 1| Labels | Item 1 | Item 2 | Item 3 | Item 4 |
| 2| name | yes | no | yes | yes |
| 3| price | yes | no | yes | yes |
| 4| tag | yes | no | yes | yes |
| 5| desc | yes | no | yes | yes |
| 6| loc | yes | no | yes | yes |
| 7| ref | yes | no | yes | yes |
| 8| obj | yes | no | yes | yes |
| 9| rand | yes | no | yes | yes |
|10| rand2 | yes | no | yes | yes |
|11| rand3 | yes | no | yes | yes |
|12| rand4 | yes | no | yes | yes |
注:1到12和A到E不在sheet
范围内如何 select 第 1 行和第 5 行到第 10 行的范围 A
、C
、E
得到以下结果? :
| | A | C | E |
| 1| Labels | Item 2 | Item 4 |
| 5| desc | no | yes |
| 6| loc | no | yes |
| 7| ref | no | yes |
| 8| obj | no | yes |
| 9| rand | no | yes |
|10| rand2 | no | yes |
注意:我留下了 1、5、6、...、10 和 A、C、E 只是为了更好地理解输出。我不希望它们出现在我的数据中,我只想要 sheet
中的数据我得到了类似这样的行范围的东西:SELECT A,C,E LIMIT 6 OFFSET 4
但是我错过了第 1 行并且找不到如何在同一个查询中添加它。
尝试:
=QUERY(A1:E; "select A,C,E limit 6 offset 3"; 1)
如果您正在寻找使用 Google 脚本的解决方案:
如果要考虑的范围将由用户手动选择,您可能有兴趣使用 getActiveRangeList()
文档:https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getactiverangelist
如果要考虑的范围是固定的并且可以集成到您的脚本中,您可能会对使用 getRangeList()
文档:https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getrangelista1notations
请注意,如果您想在脚本中迭代 rangeList,您还需要使用 getRanges()
检索列表的不同范围。
示例:
var rangeList = ss.getActiveRangeList();
var myRanges = rangeList.getRanges();
for (i = 0; i < myRanges.length; i++) {
...
}
希望对您有所帮助。 干杯
有查询:
=query(filter({row(A1:A),A1:E&""},A1:A<>""), "Select Col2, Col4, Col6 where Col1=1 or Col1>=5 and Col1<=10")
带过滤器:
=filter({A1:A & "",C1:C&"", E1:E& ""},((row(A1:A)=1)+(row(A1:A)>=5)*(row(A1:A)<=10))>0)