如何仅获取范围内的过滤值? [英] How to get only the filtered values from a range?

查看:72
本文介绍了如何仅获取范围内的过滤值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,上面有一些数据.第一列包含ID,以升序排列的连续数字序列(ID:1、2、3、4、5),第二列包含未排序的名称(名称:C,B,A,D,E). 在应用任何过滤器之前,.getSelection().getCurrentCell().getValues().getDisplayValues()函数将向我返回所需单元格的正确内容.

I have a table with some data. The first column contains IDs, a continuous series of numbers in ascending order (ID: 1, 2, 3, 4, 5), the second column contains unsorted names (NAME: C, B, A, D, E). Until I apply any filters, .getSelection().getCurrentCell().getValues() or .getDisplayValues() function returns me the correct contents of the desired cells.

然后我将过滤器应用于两列,并按字母顺序对第二列进行排序.第一行变为:ID:3、2、1、4、5.例如,我从第一行(3A)中选择项目,但脚本会在应用过滤器(1C)之前返回这些单元格中的值.

Then I apply filter to both columns and sort the second column alphabetically. First col becomes so: ID: 3, 2, 1, 4, 5. I select for example items from first row ( 3A ) but script returns me values that were in those cells before applying the filter ( 1C ).

因此,我基本上需要获取应用过滤器后出现的选定值.

So I basically need to get selected values that appears after filter was applied.

推荐答案

过滤器用于隐藏视图中的数据.无法通过任何.get*()方法获取该数据.但是,所有range.copy*()方法都会将过滤后的值复制到所需范围.如果您要复制用例,请使用

Filters are used to hide the data from view. It is not possible to get that data through any of .get*() methods. However, all range.copy*() methods will copy filtered values to the desired range. If your use case is copying, use

如果您需要直接访问用于脚本操作的值,则可以:

If you need direct access to values for script manipulation, you can:

  • getValues()并使用JavaScript或

  • getValues() and filter it programmatically in JavaScript or

使用查询端点(/gviz/tq)来获取数据

Use query endpoint(/gviz/tq) to get the data or

使用 Sheets api获取数据

使用range.copy*()getValues()从新范围将过滤的值复制到另一个范围,或者

Copy filtered values to another range using range.copy*() and getValues() from the new range or

这篇关于如何仅获取范围内的过滤值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆