google-apps-script - 向数据透视表添加过滤器

标签 google-apps-script google-sheets filter pivot-table

我在脚本中创建了数据透视表。假设这个数据透视表被命名为 数据透视表 .我想给这个表添加一个过滤器,所以我使用 过滤条件 类来实现这一点。

我可以做这样的事情:

pivotTable.addFilter(colNumber, SpreadsheetApp.newFilterCriteria().setVisibleValues(["dog", "cat"]).build());

执行此函数后,在数据透视表 仅保留索引为 的列中的行colNumber 具有值“猫”或“狗”。现在我想做这样的事情:
pivotTable.addFilter(anotherColNumber, SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build());

...然后我得到异常:
Exception: The pivot table filter criteria should only contain visible values.

我的问题是:
  • 我不明白我收到的异常(“可见值”究竟是什么意思?)。
  • 我不知道我做错了什么。
  • 我找不到这个或类似问题的答案。
  • 我发现的大多数答案都与 javascript 有关,所以它们对我没有帮助。
  • 文档中没有示例 https://developers.google.com/apps-script/reference/spreadsheet .

  • 感谢您的帮助!

    最佳答案

    不幸的是,目前,似乎无法以编程方式操作数据透视表中的“按条件过滤”。只能使用 setVisibleValues() 操作“按值过滤” .考虑创建一个 issue in the issuetracker添加一颗星(左上角的★) issue创建者 Fi Teach

    关于google-apps-script - 向数据透视表添加过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60919232/

    相关文章:

    google-sheets - "format"true/false 类似于 Google 表格中的 "yes/no"

    python - 使用 Ansible 从一行文本中提取两个字符串

    c# - 我如何过滤所有字段名称的 C# dataGridView?

    r - 按日期和 ID 过滤重复项

    google-apps-script - Google 可视化柱形图将查询中的数据列设置为角色 : "Style"

    Javascript使用电子表格范围A1表示法从二维数组中提取子数组

    google-apps-script - match() 不适用于数字字段

    google-apps-script - 在提交Google表单之前验证日期

    google-apps-script - 每次调用gapi.auth.authorize的替代方法

    使用 Apps 脚本作为源数据的 Google Drive 托管页面中的 Jquery 脚本问题