Python
xlrd
XLRDError
xlsx
Excel

xlrd.biffh.XLRDError Excel xlsx file; not supported

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

The `xlrd.biffh.XLRDError: Excel xlsx file; not supported` error is a common issue faced by Python developers working with spreadsheet data, particularly when using the `xlrd` library. This error indicates a mismatch between the file type being read and the support provided by the `xlrd` library. In this article, we will dive into the details of this error, explore its causes, and provide solutions.

Understanding the Error

What is `xlrd`?

`xlrd` is a Python library used for reading data and formatting information from Excel files in the `.xls` format. Historically, it supported both `.xls` and `.xlsx` formats, although its primary focus and compatibility have been with `.xls` files.

The Error Explained

The error message itself: `xlrd.biffh.XLRDError: Excel xlsx file; not supported` suggests that the `xlrd` library is attempting to open an `.xlsx` file, which it no longer supports.

Cause of the Error

The root cause of this error lies in updates made to the `xlrd` library. As of version 2.0.0, `xlrd` dropped support for `.xlsx` files for security reasons related to the Excel binary format. Consequently, attempting to open an `.xlsx` file using `xlrd` will throw this error.

Solutions to the Error

Alternative Libraries

Given that `xlrd` no longer supports `.xlsx` files, developers must turn to alternatives. Here are some popular Python libraries that support `.xlsx` files:

  1. `openpyxl`: A Python library that allows you to read and write `.xlsx` files. It is widely used and actively maintained.
  2. `pandas`: A powerful data manipulation library, which can read `.xlsx` files using the `pd.read_excel()` method. By default, this method relies on `openpyxl` if the file is `.xlsx`.
  3. `pyxlsb`: Specifically designed for reading and writing `.xlsb` (Excel Binary) files, although not a solution for `.xlsx` files directly, it's noteworthy for different Excel formats.

Code Example: Migrating to `openpyxl`

Here’s how you can modify your code to use `openpyxl` instead of `xlrd` for `.xlsx` files:


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms