pola-rs/polars · error · ValueError

no matching sheet found when `sheet_name` is

Error message

no matching sheet found when `sheet_name` is {name!r}

What it means

When `sheet_name` is given, `_get_sheet_names` checks each requested name against the workbook's known sheet names and raises a `ValueError` for the first name not present, including the missing name in the message.

Solutions

  1. Print available names via the same parser (e.g. inspect workbook sheets) and correct the spelling/case
  2. Use `sheet_id` instead if the position is stable
  3. Handle multi-sheet reads defensively by checking names before calling

Example fix

// before
pl.read_excel(f, sheet_name='Sheet1 ')
// after
names = [ws['name'] for ws in workbook_sheets]
pl.read_excel(f, sheet_name=next(n for n in names if n.strip() == 'Sheet1'))
Defensive patterns

Strategy: validation

Validate before calling

known = {ws['name'] for ws in sheets}
assert all(n in known for n in requested_names), f'unknown sheets: {set(requested_names) - known}'

Try / catch

try:
    df = pl.read_excel(f, sheet_name=name)
except ValueError as e:
    if 'no matching sheet found' in str(e):
        df = pl.read_excel(f)  # or log available sheet names and re-raise
    else:
        raise

Prevention

When it happens

Trigger: `pl.read_excel(f, sheet_name='Sheet 1')` where the workbook has no sheet named exactly 'Sheet 1'; also list forms like `sheet_name=['A','B']` where any one is absent.

Common situations: Sheet renamed or deleted after the code was written; case/whitespace mismatches ('sheet1' vs 'Sheet1'); reading a different workbook version with different tabs.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/ce5fcba6ec86e104. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/spreadsheet/functions.py:817

        sheet_names.append(name)
        return_multiple_sheets = False
    elif sheet_id == 0:
        sheet_names.extend(ws["name"] for ws in worksheets)
        return_multiple_sheets = True
    else:
        return_multiple_sheets = (
            (isinstance(sheet_name, Sequence) and not isinstance(sheet_name, str))
            or isinstance(sheet_id, Sequence)
            or sheet_id == 0
        )
        if names := (
            (sheet_name,) if isinstance(sheet_name, str) else sheet_name or ()
        ):
            known_sheet_names = {ws["name"] for ws in worksheets}
            for name in names:
                if name not in known_sheet_names:
                    msg = f"no matching sheet found when `sheet_name` is {name!r}"
                    raise ValueError(msg)
                sheet_names.append(name)
        else:
            ids = (sheet_id,) if isinstance(sheet_id, int) else sheet_id or ()
            sheet_names_by_idx = {
                idx: ws["name"]
                for idx, ws in enumerate(worksheets, start=1)
                if (sheet_id == 0 or ws["index"] in ids or ws["name"] in names)
            }
            for idx in ids:
                if (name := sheet_names_by_idx.get(idx)) is None:
                    msg = f"no matching sheet found when `sheet_id` is {idx}"
                    raise ValueError(msg)
                sheet_names.append(name)

    return sheet_names, return_multiple_sheets  # type: ignore[return-value]


def _initialise_spreadsheet_parser(

View on GitHub (pinned to fe841f959e)