Skip to content

Autofilter ​

AutoFilter ​

interface

A worksheet's autofilter: the filtered region plus any per-column criteria narrowing it. A bare range (no columns) is just the header-row dropdowns Excel draws; adding FilterColumns records the criteria a column is actively filtered by.

ts
interface AutoFilter {
  /** The filtered region in canonical `A1:C10` form; its top row is the header the dropdowns sit on. */
  readonly ref: string;
  /** The columns actively narrowed, each addressed by its offset from the range's left edge. Empty
   *  when the filter only draws dropdowns without hiding any row. */
  readonly columns: readonly FilterColumn[];
}

CustomFilter ​

interface

A column narrowed to one or two operator predicates (> 6, <> "draft"). Two predicates are AND-combined when and is set, else OR-combined; Excel permits at most two.

ts
interface CustomFilter {
  readonly kind: 'custom';
  readonly and: boolean;
  readonly predicates: readonly CustomFilterPredicate[];
}

CustomFilterOperator ​

type

ts
type CustomFilterOperator =
  | 'equal'
  | 'notEqual'
  | 'lessThan'
  | 'lessThanOrEqual'
  | 'greaterThan'
  | 'greaterThanOrEqual';

CustomFilterPredicate ​

interface

ts
interface CustomFilterPredicate {
  readonly operator: CustomFilterOperator;
  /** The comparison operand, kept as its raw string form (a number, or wildcard text like `a*`). */
  readonly val: string;
}

FilterColumn ​

interface

One filtered column, addressed by its 0-based offset (colId) from the filter range's left edge.

ts
interface FilterColumn {
  readonly colId: number;
  readonly criteria: FilterCriteria;
}

FilterCriteria ​

type

The two criteria kinds this library models: a discrete value set, or operator predicates.

ts
type FilterCriteria = ValuesFilter | CustomFilter;

isCustomFilterOperator ​

const

Narrow a raw operator attribute to a known CustomFilterOperator.

ts
const isCustomFilterOperator: (value: string) => value is CustomFilterOperator

ValuesFilter ​

interface

A column narrowed to a discrete set of allowed values: the checkbox list in Excel's dropdown. A row survives when its cell in this column matches one of values (or is blank, when blank is set).

ts
interface ValuesFilter {
  readonly kind: 'values';
  readonly values: readonly string[];
  readonly blank: boolean;
}

Released under the MIT License.