ExcelScript.Filter interface

管理表格列的筛选。

注解

示例

/**
 * This script adds a table filter to only show the top 10% of values 
 * belonging to a particular column.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the first table on the current worksheet.
    const table = workbook.getActiveWorksheet().getTables()[0];

    // Get the filter for the "PageViews" table column.
    const pageViewFilter : ExcelScript.Filter = table.getColumnByName("PageViews").getFilter();

    // Apply a filter to only show the rows with the top 10% of values in this column.
    pageViewFilter.applyTopPercentFilter(10);
}

方法

apply(criteria)

在给定列中应用给定的筛选条件。

applyBottomItemsFilter(count)

将“Bottom Item”筛选器应用于列,以获取给定数量的元素。

applyBottomPercentFilter(percent)

将“Bottom Percent”筛选器应用于列,以获取给定比例的元素。

applyCellColorFilter(color)

将“Cell Color”筛选器应用于列,以获取给定颜色。

applyCustomFilter(criteria1, criteria2, oper)

将“图标”筛选器应用于给定条件字符串的列。

applyDynamicFilter(criteria)

将“Dynamic”筛选器应用于列。

applyFontColorFilter(color)

将“Font Color”筛选器应用于列,以获取给定颜色。

applyIconFilter(icon)

将“图标”筛选器应用于给定图标的列。

applyTopItemsFilter(count)

将“Top Item”筛选器应用于列,以获取给定数量的元素。

applyTopPercentFilter(percent)

将“Top Percent”筛选器应用于列,以获取给定比例的元素。

applyValuesFilter(values)

将“Values”筛选器应用于列,获取给定值。

clear()

清除给定列上的 filter。

getCriteria()

给定列上当前应用的筛选器。

方法详细信息

apply(criteria)

在给定列中应用给定的筛选条件。

apply(criteria: FilterCriteria): void;

参数

criteria
ExcelScript.FilterCriteria

要应用的条件。

返回

void

applyBottomItemsFilter(count)

将“Bottom Item”筛选器应用于列,以获取给定数量的元素。

applyBottomItemsFilter(count: number): void;

参数

count

number

要显示的底部元素的数量。

返回

void

applyBottomPercentFilter(percent)

将“Bottom Percent”筛选器应用于列,以获取给定比例的元素。

applyBottomPercentFilter(percent: number): void;

参数

percent

number

要显示的底部元素的百分比。

返回

void

applyCellColorFilter(color)

将“Cell Color”筛选器应用于列,以获取给定颜色。

applyCellColorFilter(color: string): void;

参数

color

string

要显示的单元格的背景颜色。

返回

void

applyCustomFilter(criteria1, criteria2, oper)

将“图标”筛选器应用于给定条件字符串的列。

applyCustomFilter(
            criteria1: string,
            criteria2?: string,
            oper?: FilterOperator
        ): void;

参数

criteria1

string

第一个条件字符串。

criteria2

string

可选。 第二个条件字符串。

oper
ExcelScript.FilterOperator

可选。 说明这两个条件如何联接的运算符。

返回

void

示例

/**
 * The script filters rows from a table based on numerical values.
 */ 
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the current worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const table = currentSheet.getTables()[0];

  // Filter to only show rows with values in the "Sales" column that are 
  // greater than or equal to 2000.
  table.getColumnByName("Sales").getFilter().applyCustomFilter(">=2000");
}

applyDynamicFilter(criteria)

将“Dynamic”筛选器应用于列。

applyDynamicFilter(criteria: DynamicFilterCriteria): void;

参数

criteria
ExcelScript.DynamicFilterCriteria

要应用的动态条件。

返回

void

示例

/**
 * This script applies a filter to a table that filters it 
 * to only show rows with dates from the previous month.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the table named "ReportTable".
  const table = workbook.getTable("ReportTable");

  // Get the column with the header "Date".
  const dateColumn = table.getColumnByName("Date");

  // Apply a dynamic filter to the column. 
  // `lastMonth` will only show rows with a date from the previous month.
  dateColumn.getFilter().applyDynamicFilter(ExcelScript.DynamicFilterCriteria.lastMonth);
}

applyFontColorFilter(color)

将“Font Color”筛选器应用于列,以获取给定颜色。

applyFontColorFilter(color: string): void;

参数

color

string

要显示的单元格的字体颜色。

返回

void

applyIconFilter(icon)

将“图标”筛选器应用于给定图标的列。

applyIconFilter(icon: Icon): void;

参数

icon
ExcelScript.Icon

要显示的单元格图标。

返回

void

applyTopItemsFilter(count)

将“Top Item”筛选器应用于列,以获取给定数量的元素。

applyTopItemsFilter(count: number): void;

参数

count

number

要显示的顶部元素的数量。

返回

void

applyTopPercentFilter(percent)

将“Top Percent”筛选器应用于列,以获取给定比例的元素。

applyTopPercentFilter(percent: number): void;

参数

percent

number

要显示的顶部元素的百分比。

返回

void

applyValuesFilter(values)

将“Values”筛选器应用于列,获取给定值。

applyValuesFilter(values: Array<string | FilterDatetime>): void;

参数

values

Array<string | ExcelScript.FilterDatetime>

要显示的值的列表。 这必须是字符串数组或对象的数组 ExcelScript.FilterDateTime

返回

void

示例

/**
 * This script applies a filter to a table so that it only shows rows with "Needs Review" in the "Type" column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the workbook.
  const table = workbook.getTables()[0];

  // Apply the filter to the "Type" column.
  const typeColumn = table.getColumnByName("Type");
  typeColumn.getFilter().applyValuesFilter(["Needs Review"]);
}

clear()

清除给定列上的 filter。

clear(): void;

返回

void

示例

/**
 * This script shows how to clear a filter from a table column.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the first table in the workbook.
  const table = workbook.getTables()[0];

  // Clear the filter for the table column named "Status".
  const statusColumnFilter = table.getColumn("Status").getFilter();
  statusColumnFilter.clear();
}

getCriteria()

给定列上当前应用的筛选器。

getCriteria(): FilterCriteria;

返回