ExcelScript.AutoFilter interface
表示 AutoFilter
对象。 自动筛选根据单元格内容将 Excel 列中的值转换为特定筛选器。
注解
示例
/**
* This script creates an autoFilter on the worksheet that filters out rows based on column values.
* The autoFilter filters to only include rows that have a value in column C in the lowest 10 values
* (of column C values).
*/
function main(workbook: ExcelScript.Workbook) {
// Get the autoFilter of the first table in the current worksheet.
const currentSheet = workbook.getActiveWorksheet();
const dataRange = currentSheet.getUsedRange();
const autoFilter = currentSheet.getAutoFilter();
// Add a filter that will only show the rows with the lowest 10 values in column C
// (index 2, assuming the used range spans from at least A:C).
autoFilter.apply(dataRange, 2, {
criterion1: "10",
filterOn: ExcelScript.FilterOn.bottomItems
});
}
方法
apply(range, column |
将自动筛选器应用于区域。 如果指定了列索引和筛选条件,则筛选列。 |
clear |
清除自动筛选的列筛选条件。 |
clear |
清除自动筛选的筛选条件和排序状态。 |
get |
在自动筛选区域中保留所有筛选条件的数组。 |
get |
指定是否启用自动筛选。 |
get |
指定自动筛选是否具有筛选条件。 |
get |
返回对象, |
reapply() | 应用区域上当前指定的 AutoFilter 对象。 |
remove() | 删除区域的自动筛选。 |
方法详细信息
apply(range, columnIndex, criteria)
将自动筛选器应用于区域。 如果指定了列索引和筛选条件,则筛选列。
apply(
range: Range | string,
columnIndex?: number,
criteria?: FilterCriteria
): void;
参数
- range
-
ExcelScript.Range | string
将应用自动筛选的范围。
- columnIndex
-
number
应用自动筛选的从零开始的列索引。
- criteria
- ExcelScript.FilterCriteria
筛选条件。
返回
void
示例
/**
* This script applies a filter to a table so that
* only rows with values in column 1 that start with "L" are shown.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the autoFilter of the first table in the current worksheet.
const table = workbook.getActiveWorksheet().getTables()[0];
const autoFilter = table.getAutoFilter();
// Filter to only include values that start with "L".
const filterCriteria: ExcelScript.FilterCriteria = {
filterOn: ExcelScript.FilterOn.custom,
criterion1: "L*"
};
// Apply the filter to column 1 (zero-based).
autoFilter.apply(table.getRange(), 1, filterCriteria);
}
clearColumnCriteria(columnIndex)
清除自动筛选的列筛选条件。
clearColumnCriteria(columnIndex: number): void;
参数
- columnIndex
-
number
从零开始的列索引,表示需要清除哪个列筛选器。 如果不支持索引值 (例如,如果值为负数,或者该值大于) 范围内的可用列数, InvalidArgument
则会引发错误。
返回
void
clearCriteria()
清除自动筛选的筛选条件和排序状态。
clearCriteria(): void;
返回
void
示例
/**
* This script clears any applied criteria from the worksheet's autoFilter.
*/
function main(workbook: ExcelScript.Workbook) {
const currentSheet = workbook.getActiveWorksheet();
// Clear all the criteria currently applied to the autoFilter.
currentSheet.getAutoFilter().clearCriteria();
}
getCriteria()
getEnabled()
指定是否启用自动筛选。
getEnabled(): boolean;
返回
boolean
getIsDataFiltered()
指定自动筛选是否具有筛选条件。
getIsDataFiltered(): boolean;
返回
boolean
getRange()
返回对象, Range
该对象表示自动筛选应用到的范围。
Range
如果没有与 AutoFilter 关联的对象,则此方法返回 undefined
。
getRange(): Range;
返回
reapply()
应用区域上当前指定的 AutoFilter 对象。
reapply(): void;
返回
void
remove()
删除区域的自动筛选。
remove(): void;
返回
void