ExcelScript.PivotFilters interface

Интерфейс, представляющий все PivotFilter, применяемые в настоящее время к заданному PivotField.

Свойства

dateFilter

Текущий фильтр даты сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

labelFilter

Текущий фильтр меток сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

manualFilter

В настоящее время применяется фильтр PivotField вручную. Это свойство имеет значение, null если фильтр значений не применяется.

valueFilter

Текущий фильтр значений сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

Сведения о свойстве

dateFilter

Текущий фильтр даты сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

dateFilter?: PivotDateFilter;

Значение свойства

Примеры

/**
 * This script applies a filter to a PivotTable that filters out rows 
 * that aren't from this month.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the "Date Recorded" field to filter. 
  // The data in this field must be dates in order for the filter to work.
  const pivot = workbook.getPivotTables()[0];
  const rowHierarchy = pivot.getRowHierarchy("Date Recorded");
  const rowField = rowHierarchy.getFields()[0];

  // Apply the date filter.
  rowField.applyFilter({
    dateFilter: {
      // Setting the condition to `thisMonth` means items that are before or
      // after this month will not be displayed.
      condition: ExcelScript.DateFilterCondition.thisMonth
    }
  });
}

labelFilter

Текущий фильтр меток сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

labelFilter?: PivotLabelFilter;

Значение свойства

Примеры

/**
 * This script filters items that start with "L" from the "Type" field
 * of the "Farm Sales" PivotTable.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable.
  const pivotTable = workbook.getActiveWorksheet().getPivotTable("Farm Sales");

  // Get the "Type" field.
  const field = pivotTable.getHierarchy("Type").getPivotField("Type");

  // Filter out any types that start with "L" (such as "Lemons" and "Limes").
  const filter: ExcelScript.PivotLabelFilter = {
    condition: ExcelScript.LabelFilterCondition.beginsWith,
    substring: "L",
    exclusive: true
  };

  // Apply the label filter to the field.
  field.applyFilter({ labelFilter: filter });
}

manualFilter

В настоящее время применяется фильтр PivotField вручную. Это свойство имеет значение, null если фильтр значений не применяется.

manualFilter?: PivotManualFilter;

Значение свойства

Примеры

/**
 * This script adds a manual filter to a PivotTable. 
 */
function main(workbook: ExcelScript.Workbook)
{
  // Get the first PivotTable in the workbook.
  const pivot = workbook.getPivotTables()[0];

  // Get the hierarchy to use as the filter.
  const location = pivot.getHierarchy("Location");

  // Use "Location" as the FilterHierarchy.
  pivot.addFilterHierarchy(location);

  // Select items for the filter.
  // Note that hierarchies and fields have a 1:1 relationship in Excel,
  // so `getFields()[0]` always gets the correct field.
  location.getFields()[0].applyFilter({
    manualFilter: {
      selectedItems: ["Seattle", "Chicago"]
    }
  });
}

valueFilter

Текущий фильтр значений сводного поля. Это свойство имеет значение, null если фильтр значений не применяется.

valueFilter?: PivotValueFilter;

Значение свойства

Примеры

/**
 * This script applies a PivotValueFilter to the first row hierarchy in the PivotTable.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the PivotTable on the current worksheet.
  let sheet = workbook.getActiveWorksheet();
  let pivotTable = sheet.getPivotTables()[0];

  // Get the first row hierarchy to use as the field which gets filtered.
  let rowHierarchy = pivotTable.getRowHierarchies()[0];

  // Get the first data hierarchy to use as the values for filtering the rows.
  let dataHierarchy = pivotTable.getDataHierarchies()[0];

  // Create a filter that excludes values greater than 500.
  let filter: ExcelScript.PivotValueFilter = {
    condition: ExcelScript.ValueFilterCondition.greaterThan,
    comparator: 500,
    value: dataHierarchy.getName()
  };

  // Apply the filter.
  rowHierarchy.getPivotField(rowHierarchy.getName()).applyFilter({
    valueFilter: filter
  });
}