使用Google Apps脚本在范围内启用数据过滤器 [英] Enable data filters on a range with Google Apps Script

查看:146
本文介绍了使用Google Apps脚本在范围内启用数据过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在某个范围内通过Google表格中的脚本启用数据过滤器?目前这可以手动完成,但我不想选择范围,然后点击数据,然后打开过滤器。



我知道过滤器会留在现有的表格中。然而,我尝试为通过脚本生成的新电子表格应用过滤器。



我的想法是:

  function foo(){
var spreadsheet = SpreadsheetApp.getActive();
var infoSheet = spreadsheet.insertSheet('sheetName',spreadsheet.getNumSheets());

infoSheet.getRange(1,1,5,5)。 - >启用过滤器?
...
}

如何以编程方式实现我的目标?

解决方案

简短答案是否。
似乎GAS既不支持获取,也不支持为列设置过滤条件,至少根据这个未解决的问题

另一种解决方案是在GAS端进行过滤和排序,并将不同的结果推入不同的列或表单。


Is there a way to enable data filters by script in a Google Sheet for a certain range? Currently this can be doen manually, but I do not want to select a range, then click 'Data', and then turn on filter.

I know that the filter will remain in an existing sheet. However, I try to apply a filter for a new spreadsheet that is generated via scripting.

My idea is:

function foo() {
  var spreadsheet = SpreadsheetApp.getActive();
  var infoSheet = spreadsheet.insertSheet('sheetName', spreadsheet.getNumSheets());

  infoSheet.getRange(1, 1, 5, 5). -> enable filter?
  ...
}

How can I achieve my goal programmatically?

解决方案

A short answer would be "No". It seems that GAS supports neither getting, nor setting Filter criteria for columns, at least according to this open issue.

An alternative solution would be to do the filtering and sorting on GAS side, and push the distinct results into different columns or sheets.

这篇关于使用Google Apps脚本在范围内启用数据过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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