qax-os/excelize · error

unknown operator: %s

Error message

unknown operator: %s

What it means

The AutoFilter expression parser tokenizes filter strings like 'x < 5 or y > 2' into conditions and operators. This error is thrown when a token positioned as an operator is not a recognized operator (and/or or the comparison shorthand), so the filter expression cannot be understood.

Source

Thrown at errors.go:399

	return fmt.Errorf("base field %s does not exist in shared items", field)
}

// newStreamSetRowError defined the error message on the stream writer
// receiving the non-ascending row number.
func newStreamSetRowError(row int) error {
	return fmt.Errorf("row %d has already been written", row)
}

// newStreamSetRowOrderError defined the error message on calling the SetRow
// function before the order function.
func newStreamSetRowOrderError(name string) error {
	return fmt.Errorf("must call the %s function before the SetRow function", name)
}

// newUnknownFilterTokenError defined the error message on receiving a unknown
// filter operator token.
func newUnknownFilterTokenError(token string) error {
	return fmt.Errorf("unknown operator: %s", token)
}

// newUnsupportedChartType defined the error message on receiving the chart
// type are unsupported.
func newUnsupportedChartType(chartType ChartType) error {
	return fmt.Errorf("unsupported chart type %d", chartType)
}

// newUnsupportedPivotCacheSourceType defined the error message on receiving the
// source type of pivot table cache.
func newUnsupportedPivotCacheSourceType(sourceType string) error {
	return fmt.Errorf("unsupported pivot table cache source type: %s", sourceType)
}

// newUnzipSizeLimitError defined the error message on unzip size exceeds the
// limit.
func newUnzipSizeLimitError(unzipSizeLimit int64) error {
	return fmt.Errorf("unzip size exceeds the %d bytes limit", unzipSizeLimit)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Use only the supported operators in filter expressions: and, or, and the comparison forms the library documents for AutoFilter criteria.
  2. Print/tokenize your criteria string and remove stray or misspelled tokens between conditions.
  3. Replace SQL-style '&&'/'||' with 'and'/'or'.
  4. Split complex filters into multiple simpler AutoFilter expressions if the combined string still fails.

Example fix

// before
f.AutoFilter("Sheet1", "A1:D10", []excelize.AutoFilterOptions{
    {Column: "A", Expression: "x > 1 && x < 10"},
})
// after
f.AutoFilter("Sheet1", "A1:D10", []excelize.AutoFilterOptions{
    {Column: "A", Expression: "x > 1 and x < 10"},
})
Defensive patterns

Strategy: validation

Validate before calling

var validOps = map[string]bool{"and": true, "or": true}
func tokensValid(expr string) bool {
    for _, tok := range strings.Fields(expr) {
        if validOps[tok] {
            continue
        }
    }
    // stricter: reject SQL-style operators up front
    return !strings.ContainsAny(expr, "&|") &&
        !strings.Contains(expr, "&&") && !strings.Contains(expr, "||")
}

Try / catch

err := f.AutoFilter(sheet, rangeRef, opts)
if err != nil {
    if strings.Contains(err.Error(), "unknown operator") {
        return fmt.Errorf("autofilter expression %q has an unsupported operator token", expr)
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.AutoFilter with a criteria expression containing a misspelled or unsupported operator token, e.g. 'A1 > 10 && B1 < 5' (using && instead of 'and') or 'x equals 5' in a context expecting 'and'/'or' between conditions.

Common situations: Building filter strings by string concatenation with SQL-style operators; localizing operators; typos like 'adn', 'ore', or stray tokens left after splitting the expression.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/a0163724b7f0cfe6. Report an issue: GitHub.