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

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

问题描述

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

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.

我的想法是:

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.

另一种解决方案是在 GAS 端进行过滤和排序,并将不同的结果推送到不同的列或工作表中.

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天全站免登陆