# Reading

Fast value extraction with `ExcelReader`.

[API reference](<https://justybase.github.io/xlspy/api/index.md>) · [Guide](<https://justybase.github.io/xlspy/usage/index.md>)

## ExcelReader

```
ExcelReader(path: str | PathLike[str] | IO[bytes] | None = None, use_memory_stream_for_xlsb: bool = True, errors: str = 'legacy')
```

A fast reader of cell values from XLSX, XLSM and XLSB files.

Use it as a context manager::

```
with ExcelReader("report.xlsb") as reader:
    rows = reader.read_all(reader.get_sheet_names()[0])
```

Error cells come back as CellError strings (`"error:#DIV/0!"`); with `errors="openpyxl"` they are plain text such as `"#DIV/0!"`. For styles, coordinates or editing use `load_workbook`.

Examples:

Stream values without building the workbook model:

```
from xlspy import ExcelReader

with ExcelReader("report.xlsb") as reader:
    print(reader.get_sheet_names())
    for row in reader.get_rows("Sales"):
        print(row)
```

Formula text instead of cached values:

```
with ExcelReader("report.xlsx") as reader:
    rows = reader.read_all("Sales", data_only=False)
```

**See Also**

`load_workbook` when you need coordinates, styles or edits; the tutorial page `reading` for a comparison of the three read modes.

### open

```
open(path: str | PathLike[str] | IO[bytes]) -> None
```

Open `path` and read its sheet list, shared strings and styles.

`path` is a file name, a `scheme://` URI opened through fsspec, or a binary file object such as `io.BytesIO`. An XLSB package is detected by its `xl/workbook.bin` part, any other package is read as XLSX/XLSM. Raises InvalidFileError for a damaged file.

### close

```
close() -> None
```

Close the file; calling it again does nothing.

### get\_sheet\_names

```
get_sheet_names() -> list[str]
```

The sheet names, in workbook order, chartsheets included.

A chartsheet has no cells: `get_rows` yields nothing for it. See `get_chartsheet_names`.

### get\_chartsheet\_names

```
get_chartsheet_names() -> list[str]
```

The names of the sheets without cells (chartsheets and dialog sheets), in workbook order.

### read\_part

```
read_part(path: str) -> bytes | None
```

The bytes of a package part, or None when the package has no such part.

### get\_sheet\_index

```
get_sheet_index(sheet_name: str) -> int
```

Return the 0-based position of `sheet_name`; raises ValueError when absent.

### get\_rows

```
get_rows(sheet_name: str, *, data_only: bool = True, streaming: bool = False) -> Generator[list[Any], None, None]
```

Yield values or formula text; streaming=True opts into incremental XLSB.

### read\_all

```
read_all(sheet_name: str, *, data_only: bool = True, streaming: bool = False) -> list[list[Any]]
```

Return all rows of a sheet as a list; see `get_rows`.

### to\_pandas

```
to_pandas(sheet_name: str | int | None = 0, **kwargs: Any) -> Any
```

Read a sheet into a pandas DataFrame; see `read_dataframe`.

The reader stays open; the returned frame owns its data.

### to\_polars

```
to_polars(sheet_name: str | int | None = 0, **kwargs: Any) -> Any
```

Read a sheet into a polars DataFrame; see `read_dataframe`.

### get\_comments

```
get_comments(sheet_name: str) -> dict[str, Comment]
```

Return classic note text and authors, without reading worksheet rows.

The compatibility notes that link Excel to a threaded conversation are not included; use `get_threaded_comments` for those conversations.

### get\_threaded\_comments

```
get_threaded_comments(sheet_name: str) -> dict[str, ThreadedComment]
```

Return the sheet's Excel 365 conversations, keyed by cell reference.

Classic notes are read by `get_comments`; this method reads only the modern threaded part, so both kinds can be inspected separately.

### get\_defined\_names

```
get_defined_names() -> list[DefinedName]
```

Return global and worksheet-local user names (not built-in names).
