Class SortSpec
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
详细文档
getBackgroundColor()
返回用于排序的背景颜色,如果不存在,则返回 null
。
返回
Color
- 背景颜色。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceColumn()
获取排序规范作用的数据源列。如果此排序规范不针对数据源列进行操作,则返回 null
。
返回
DataSourceColumn
- 排序规范作用的数据源列。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDimensionIndex()
返回维度索引,如果未关联到本地过滤器,则返回 null
。
返回
Integer
- 维度索引。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getForegroundColor()
返回用于排序的前景颜色,如果不存在,则返回 null
。
返回
Color
- 前景色。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSortOrder()
返回排序顺序。
返回
SortOrder
- 排序顺序。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isAscending()
返回排序顺序是升序还是降序。
返回
Boolean
- 如果排序顺序为升序,则为 true
;否则为 false
。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eSortSpec\u003c/code\u003e defines the specifications for sorting data, such as sort order, colors, and the data source.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to retrieve information about the sort specification, including background and foreground colors, sort order, and the data source column being used.\u003c/p\u003e\n"],["\u003cp\u003eYou can determine if the sort order is ascending using the \u003ccode\u003eisAscending()\u003c/code\u003e method and obtain the dimension index with \u003ccode\u003egetDimensionIndex()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAll methods within \u003ccode\u003eSortSpec\u003c/code\u003e require authorization with specific scopes related to spreadsheet access.\u003c/p\u003e\n"]]],["SortSpec defines the criteria for sorting data. Key actions include retrieving the background and foreground colors used in sorting, if any. It fetches the data source column being sorted, or returns null if not present. It can retrieve the dimension index if linked to a filter. The sort order itself, along with whether the sorting is ascending, can also be obtained using the methods `getSortOrder()` and `isAscending()` respectively.\n"],null,["# Class SortSpec\n\nSortSpec\n\nThe sorting specification. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------|---------------------------------------------------------------------------|------------------------------------------------------------------------|\n| [getBackgroundColor()](#getBackgroundColor()) | [Color](/apps-script/reference/spreadsheet/color) | Returns the background color used for sorting, or `null` if absent. |\n| [getDataSourceColumn()](#getDataSourceColumn()) | [DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) | Gets the data source column the sort spec acts on. |\n| [getDimensionIndex()](#getDimensionIndex()) | `Integer` | Returns the dimension index or `null` if not linked to a local filter. |\n| [getForegroundColor()](#getForegroundColor()) | [Color](/apps-script/reference/spreadsheet/color) | Returns the foreground color used for sorting, or `null` if absent. |\n| [getSortOrder()](#getSortOrder()) | [SortOrder](/apps-script/reference/spreadsheet/sort-order) | Returns the sort order. |\n| [isAscending()](#isAscending()) | `Boolean` | Returns whether the sort order is ascending. |\n\nDetailed documentation\n----------------------\n\n### `get``Background``Color()`\n\nReturns the background color used for sorting, or `null` if absent.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The background color.\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``Data``Source``Column()`\n\nGets the data source column the sort spec acts on. Returns `null` if this sort spec is\nnot acting on a data source column.\n\n#### Return\n\n\n[DataSourceColumn](/apps-script/reference/spreadsheet/data-source-column) --- The data source column the sort spec acts 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### `get``Dimension``Index()`\n\nReturns the dimension index or `null` if not linked to a local filter.\n\n#### Return\n\n\n`Integer` --- The dimension index.\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``Foreground``Color()`\n\nReturns the foreground color used for sorting, or `null` if absent.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The foreground color.\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``Sort``Order()`\n\nReturns the sort order.\n\n#### Return\n\n\n[SortOrder](/apps-script/reference/spreadsheet/sort-order) --- The sort order.\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### `is``Ascending()`\n\nReturns whether the sort order is ascending.\n\n#### Return\n\n\n`Boolean` --- `true` if the sort order is ascending, or `false` otherwise.\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`"]]