xlrd

A Python library for extracting data and formatting from legacy Excel .xls spreadsheet files

Library
PyPI
v2.0.2
2,206 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
60 /100 Good
Development Activity 52
Maintenance 8
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
64 /100 Good
Architecture 70
Code Quality 68
Innovation 45
Learning Curve 72

xlrd is a library for developers to extract data, formatting information, and workbook structure from Microsoft Excel’s legacy binary .xls spreadsheet format. It has been scoped down deliberately: as of its README, xlrd no longer reads the newer .xlsx format at all, pointing users toward openpyxl or other tools in the python-excel ecosystem for that. Within its narrowed scope it remains actively maintained, handling cell values, dates, number formats, and workbook/sheet structure for the older Excel binary format that many legacy enterprise systems and archives still produce.

What You Get

  • A open_workbook() entry point returning a Book object with sheets addressable by name or index
  • Cell-level access to values, types, and Excel’s internal number-format/date-format information via xlrd.sheet
  • Correct conversion of Excel’s serial date values to Python datetime objects via xlrd.xldate
  • Low-level BIFF and OLE2 compound-document parsing (xlrd.biffh, xlrd.compdoc) for developers needing deeper access to .xls internals
  • A bundled runxlrd.py CLI script for quick inspection of .xls file contents from the command line

Common Use Cases

  • Reading legacy .xls files produced by older enterprise systems, exports, or archives that predate the .xlsx format
  • Batch-processing or migrating historical .xls spreadsheet data into a database or newer file format
  • Extracting cell values and dates from .xls files as part of a data pipeline where openpyxl (which does not support .xls) isn’t applicable
  • Building a lightweight CLI or script to inspect the structure of an unfamiliar .xls file without opening Excel

Under The Hood

Architecture xlrd’s core is a two-layer parser: xlrd.compdoc decodes the OLE2/Compound Document File Binary Format container that wraps an .xls file’s internal streams, and xlrd.biffh/xlrd.book/xlrd.sheet decode the BIFF (Binary Interchange File Format) record stream inside that container into a Book object holding one or more Sheet objects, each exposing rows/columns of Cell values. xlrd.formatting reconstructs Excel’s number-format definitions so callers can tell a date cell from a currency cell, and xlrd.xldate converts Excel’s numeric date serials (handling both the 1900 and 1904 epoch systems) into Python datetime values. xlrd.formula separately decodes Excel formula byte-code when present, though only computed results are exposed, not live formula re-evaluation. Tech Stack Pure Python with no runtime dependencies, packaged with a conventional setup.py/setup.cfg; xlrd/timemachine.py is a small Python 2/3 compatibility shim reflecting the library’s long history predating Python 3-only codebases. Code Quality The tests/ directory holds 14 test modules covering BIFF record parsing, date conversion edge cases, and sample .xls fixtures; CI runs via CircleCI with Codecov coverage tracking as advertised in the README badges. The codebase itself is dense, low-level byte-parsing code (book.py and sheet.py each run over 1,400-2,400 lines) reflecting the intrinsic complexity of a binary file format rather than incidental complexity. API Design The primary entry point, xlrd.open_workbook(), returns a Book whose .sheets()/.sheet_by_name() and cell-indexing methods are simple and stable, requiring little boilerplate for the common case of just reading values; the tradeoff is that the library intentionally does not attempt to support newer .xlsx files at all, so callers must branch on file format themselves if they need to support both.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers