Class PivotFilter
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
详细文档
getFilterCriteria()
返回相应透视过滤器的过滤条件。
返回
FilterCriteria
- 相应数据透视过滤器的过滤条件。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getPivotTable()
返回相应过滤条件所属的 PivotTable
。
返回
PivotTable
- 相应过滤条件所属的数据透视表。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSourceDataColumn()
返回相应过滤条件所处理的源数据列的数量。这些指数从 1 开始,例如,如果此过滤条件应用于电子表格的 A 列中的数据,则此方法会返回“1”。
返回
Integer
- 相应过滤条件所适用的源数据列的数量。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSourceDataSourceColumn()
返回过滤条件所依据的数据源列。如果数据透视表不是 {DataSourcePivotTableApi},则返回 null
。
返回
DataSourceColumn
- 过滤条件所针对的数据源列。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove()
从数据透视表中移除相应的数据透视过滤条件。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFilterCriteria(filterCriteria)
为此透视过滤条件设置过滤条件。
参数
返回
PivotFilter
- 用于链接的透视过滤条件。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-13。
[null,null,["最后更新时间 (UTC):2025-08-13。"],[[["\u003cp\u003e\u003ccode\u003ePivotFilter\u003c/code\u003e objects provide methods to access and modify filters applied to pivot tables in Google Sheets.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve filter criteria, identify the associated pivot table and source data column, and remove the filter using dedicated methods.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esetFilterCriteria()\u003c/code\u003e method allows you to define specific filtering conditions for the pivot table data.\u003c/p\u003e\n"],["\u003cp\u003eThese methods require authorization with specific scopes to interact with Google Sheets data.\u003c/p\u003e\n"]]],[],null,["# Class PivotFilter\n\nPivotFilter\n\nAccess and modify pivot table filters. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|\n| [getFilterCriteria()](#getFilterCriteria()) | [FilterCriteria](/apps-script/reference/spreadsheet/filter-criteria) | Returns the filter criteria for this pivot filter. |\n| [getPivotTable()](#getPivotTable()) | [PivotTable](/apps-script/reference/spreadsheet/pivot-table) | Returns the [PivotTable](/apps-script/reference/spreadsheet/pivot-table) that this filter belongs to. |\n| [getSourceDataColumn()](#getSourceDataColumn()) | `Integer` | Returns the number of the source data column this filter operates on. |\n| [getSourceDataSourceColumn()](#getSourceDataSourceColumn()) | [DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) | Returns the data source column the filter operates on. |\n| [remove()](#remove()) | `void` | Removes this pivot filter from the pivot table. |\n| [setFilterCriteria(filterCriteria)](#setFilterCriteria(FilterCriteria)) | [PivotFilter](#) | Sets the filter criteria for this pivot filter. |\n\nDetailed documentation\n----------------------\n\n### `get``Filter``Criteria()`\n\nReturns the filter criteria for this pivot filter.\n\n#### Return\n\n\n[FilterCriteria](/apps-script/reference/spreadsheet/filter-criteria) --- The filter criteria for this pivot filter.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Pivot``Table()`\n\nReturns the [PivotTable](/apps-script/reference/spreadsheet/pivot-table) that this filter belongs to.\n\n#### Return\n\n\n[PivotTable](/apps-script/reference/spreadsheet/pivot-table) --- The pivot table this filter belongs to.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Source``Data``Column()`\n\nReturns the number of the source data column this filter operates on. These indices are\n1-based, for example if this filter applies to data in column A of the spreadsheet this method\nreturns \"1.\"\n\n#### Return\n\n\n`Integer` --- The number of the source data column this filter applies to.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Source``Data``Source``Column()`\n\nReturns the data source column the filter operates on. Returns `null` if the pivot table\nis not a {DataSourcePivotTableApi}.\n\n#### Return\n\n\n[DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) --- The data source column the filter operates on.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `remove()`\n\nRemoves this pivot filter from the pivot table.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `set``Filter``Criteria(filterCriteria)`\n\nSets the filter criteria for this pivot filter.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------------|----------------------------------------------------------------------|-----------------------------|\n| `filter``Criteria` | [FilterCriteria](/apps-script/reference/spreadsheet/filter-criteria) | The filter criteria to set. |\n\n#### Return\n\n\n[PivotFilter](#) --- The pivot filter for chaining.\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`"]]