{"record":{"id":"ce5fcba6ec86e104","repo":"pola-rs/polars","slug":"no-matching-sheet-found-when-sheet-name-is-name","errorCode":null,"errorMessage":"no matching sheet found when `sheet_name` is {name!r}","messagePattern":"no matching sheet found when `sheet_name` is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":817,"sourceCode":"        sheet_names.append(name)\n        return_multiple_sheets = False\n    elif sheet_id == 0:\n        sheet_names.extend(ws[\"name\"] for ws in worksheets)\n        return_multiple_sheets = True\n    else:\n        return_multiple_sheets = (\n            (isinstance(sheet_name, Sequence) and not isinstance(sheet_name, str))\n            or isinstance(sheet_id, Sequence)\n            or sheet_id == 0\n        )\n        if names := (\n            (sheet_name,) if isinstance(sheet_name, str) else sheet_name or ()\n        ):\n            known_sheet_names = {ws[\"name\"] for ws in worksheets}\n            for name in names:\n                if name not in known_sheet_names:\n                    msg = f\"no matching sheet found when `sheet_name` is {name!r}\"\n                    raise ValueError(msg)\n                sheet_names.append(name)\n        else:\n            ids = (sheet_id,) if isinstance(sheet_id, int) else sheet_id or ()\n            sheet_names_by_idx = {\n                idx: ws[\"name\"]\n                for idx, ws in enumerate(worksheets, start=1)\n                if (sheet_id == 0 or ws[\"index\"] in ids or ws[\"name\"] in names)\n            }\n            for idx in ids:\n                if (name := sheet_names_by_idx.get(idx)) is None:\n                    msg = f\"no matching sheet found when `sheet_id` is {idx}\"\n                    raise ValueError(msg)\n                sheet_names.append(name)\n\n    return sheet_names, return_multiple_sheets  # type: ignore[return-value]\n\n\ndef _initialise_spreadsheet_parser(","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/spreadsheet/functions.py#L799-L835","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Sheet renamed or deleted after the code was written; case/whitespace mismatches ('sheet1' vs 'Sheet1'); reading a different workbook version with different tabs.","solutions":["Print available names via the same parser (e.g. inspect workbook sheets) and correct the spelling/case","Use `sheet_id` instead if the position is stable","Handle multi-sheet reads defensively by checking names before calling"],"exampleFix":"// before\npl.read_excel(f, sheet_name='Sheet1 ')\n// after\nnames = [ws['name'] for ws in workbook_sheets]\npl.read_excel(f, sheet_name=next(n for n in names if n.strip() == 'Sheet1'))","handlingStrategy":"validation","validationCode":"known = {ws['name'] for ws in sheets}\nassert all(n in known for n in requested_names), f'unknown sheets: {set(requested_names) - known}'","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_excel(f, sheet_name=name)\nexcept ValueError as e:\n    if 'no matching sheet found' in str(e):\n        df = pl.read_excel(f)  # or log available sheet names and re-raise\n    else:\n        raise","preventionTips":["List actual sheet names before hardcoding them","Normalize case/whitespace when matching sheet names","Prefer sheet_id when sheet names may change"],"tags":["python","polars","excel","sheet-name"],"backgroundTag":"entity-not-found","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}