Table of Contents

Method ApplyFilter

Namespace
DocWright.Spreadsheet
Assembly
DocWright.Spreadsheet.dll

ApplyFilter(int, XlsxFilterCriterion)

Gives a column of the autofilter a criterion and hides the rows that do not pass, as Excel does when a filter is applied.

public void ApplyFilter(int column, XlsxFilterCriterion criterion)

Parameters

column int

The one-based column of the sheet, inside the autofilter's range.

criterion XlsxFilterCriterion

What the column lets through; it replaces the criterion the column had.

Remarks

Every data row of the autofilter's range is looked at again: it is shown when each column's criterion lets it through and hidden otherwise. A row that was hidden by hand and passes is shown, as Excel shows it (measured); rows outside the range are not touched. Rows below the sheet's last stored cell are not looked at.

How each criterion reads a cell (measured, tools/Probe-ExcelSorts.ps1): a list of values against the text the cell shows, without regard to case, so that 5 lets through a number 5 and the text "5"; a condition with a number against a cell's number, and with text against its text, compared as a sort compares it, with the wildcards * and ? for equal and not equal; a top or bottom filter and an average over the column's numbers only, a percent being of their count, rounded down. An empty cell is equal to an empty or blank value and meets no other condition.

The file records each criterion as Excel records it, and Excel shows the rows as the file has them: it does not filter again when it opens the workbook.

Exceptions

ArgumentNullException

criterion is null.

ArgumentOutOfRangeException

The column is outside the autofilter's range.

InvalidOperationException

The sheet is not a worksheet, or has no autofilter (see SetAutoFilter(XlsxCellRange?)).

UnsupportedFeatureException

The criterion, or another column's, is one this library does not evaluate (Other).

InvalidDocumentException

A part of the workbook is malformed.