{"record":{"id":"44c181e2d88a3ca1","repo":"pola-rs/polars","slug":"f-table-named-table-name-r-not-found-in-sheet-sheet-name-r","errorCode":null,"errorMessage":"f\"table named {table_name!r} not found in sheet {sheet_name!r}\" if n_tables else f\"no named tables found in sheet {sheet_name!r} (looking for {table_name!r})\"","messagePattern":"f\"table named (.+?) not found in sheet (.+?)\" if n_tables else f\"no named tables found in sheet (.+?) \\(looking for (.+?)\\)\"","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":1222,"sourceCode":"    has_header = read_options.pop(\"has_header\", True)\n    schema_overrides = schema_overrides or {}\n    no_inference = infer_schema_length == 0\n    header: list[str | None] = []\n\n    if table_name and not sheet_name:\n        ws, sheet_name, n_tables = None, None, 0\n        for sheet in parser.worksheets:\n            n_tables += 1\n            if table_name in sheet.tables:\n                ws, sheet_name = sheet, sheet.title\n                break\n        if ws is None:\n            msg = (\n                f\"table named {table_name!r} not found in sheet {sheet_name!r}\"\n                if n_tables\n                else f\"no named tables found in sheet {sheet_name!r} (looking for {table_name!r})\"\n            )\n            raise RuntimeError(msg)\n    else:\n        ws = parser[sheet_name]\n\n    # prefer detection of actual table objects; otherwise read\n    # data in the used worksheet range, dropping null columns\n    if tables := getattr(ws, \"tables\", None):\n        table = tables[table_name] if table_name else next(iter(tables.values()))\n        rows = list(ws[table.ref])\n        if not rows:\n            return _empty_frame(raise_if_empty)\n        if has_header:\n            header.extend(cell.value for cell in rows.pop(0))\n        else:\n            header.extend(f\"column_{n}\" for n in range(len(rows[0])))\n        if table.totalsRowCount:\n            rows = rows[: -table.totalsRowCount]\n        rows_iter = rows\n    elif table_name:","sourceCodeStart":1204,"sourceCodeEnd":1240,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/spreadsheet/functions.py#L1204-L1240","documentation":"In the openpyxl engine, when `table_name` is requested the reader resolves the worksheet and looks for named tables; if the worksheet object is None (table/sheet lookup failed) it raises this RuntimeError — distinguishing between a sheet that has tables but not the requested one, and a sheet with no tables at all. It means the requested table cannot be found in the given sheet.","triggerScenarios":"`pl.read_excel('f.xlsx', engine='openpyxl', table_name='Table1', sheet_name='Data')` where Data has tables but not Table1, or where the sheet/table lookup yields None and the sheet has no tables (n_tables == 0).","commonSituations":"Typo in table name; table defined on another sheet; workbook authored without formal Excel tables (just ranges), so no named tables exist.","solutions":["Check the exact table name via openpyxl: `load_workbook(path)['Data'].tables.keys()`.","Pass the correct sheet_name where the table is defined.","Remove table_name and read the sheet range directly if no formal table exists.","Create a formal Excel table (Insert > Table) in the workbook if structured access is needed."],"exampleFix":"// before\nimport openpyxl\nwb = openpyxl.load_workbook('f.xlsx')\nprint(wb['Data'].tables)  # discover real names\n// after\npl.read_excel('f.xlsx', engine='openpyxl', table_name='CorrectTableName', sheet_name='Data')","handlingStrategy":"validation","validationCode":"import openpyxl\nws = openpyxl.load_workbook(path)[sheet_name]\ntables = dict(getattr(ws, 'tables', {}) or {})\nif table_name not in tables:\n    raise ValueError(f'tables in {sheet_name}: {list(tables)}')","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_excel(path, engine='openpyxl', table_name=table_name, sheet_name=sheet_name)\nexcept RuntimeError as e:\n    if 'not found' in str(e):\n        df = pl.read_excel(path, engine='openpyxl', sheet_name=sheet_name)\n    else:\n        raise","preventionTips":["List ws.tables keys before hardcoding a table name","Confirm the table exists on the intended sheet, not elsewhere in the workbook","Ensure authors create real Excel tables, not just header rows"],"tags":["polars","excel","openpyxl","table-not-found"],"backgroundTag":"resource-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"}