You can just iterate over the sheet:

def UseOpenpyxl(file_name):
    wb = openpyxl.load_workbook(file_name, read_only=True)
    sheet = wb.active
    rows = sheet.rows
    first_row = [cell.value for cell in next(rows)]
    data = []
    for row in rows:
        record = {}
        for key, cell in zip(first_row, row):
            if cell.data_type == 's':
                record[key] = cell.value.strip()
            else:
                record[key] = cell.value
        data.append(record)
    return data

This should scale to large files. You may want to chunk your result if the list data gets too large.

Now the openpyxl version takes about twice as long as the xlrd one:

%timeit xlrd_results = UseXlrd('foo.xlsx')
1 loops, best of 3: 3.38 s per loop

%timeit openpyxl_results = UseOpenpyxl('foo.xlsx')
1 loops, best of 3: 6.87 s per loop

Note that xlrd and openpyxl might interpret what is an integer and what is a float slightly differently. For my test data, I needed to add float() to make the outputs comparable:

def UseOpenpyxl(file_name):
    wb = openpyxl.load_workbook(file_name, read_only=True)
    sheet = wb.active
    rows = sheet.rows
    first_row = [float(cell.value) for cell in next(rows)]
    data = []
    for row in rows:
        record = {}
        for key, cell in zip(first_row, row):
            if cell.data_type == 's':
                record[key] = cell.value.strip()
            else:
                record[key] = float(cell.value)
        data.append(record)
    return data

Now, both versions give the same results for my test data:

>>> xlrd_results == openpyxl_results
True
Answer from Mike Müller on Stack Overflow
Top answer
1 of 3
25

You can just iterate over the sheet:

def UseOpenpyxl(file_name):
    wb = openpyxl.load_workbook(file_name, read_only=True)
    sheet = wb.active
    rows = sheet.rows
    first_row = [cell.value for cell in next(rows)]
    data = []
    for row in rows:
        record = {}
        for key, cell in zip(first_row, row):
            if cell.data_type == 's':
                record[key] = cell.value.strip()
            else:
                record[key] = cell.value
        data.append(record)
    return data

This should scale to large files. You may want to chunk your result if the list data gets too large.

Now the openpyxl version takes about twice as long as the xlrd one:

%timeit xlrd_results = UseXlrd('foo.xlsx')
1 loops, best of 3: 3.38 s per loop

%timeit openpyxl_results = UseOpenpyxl('foo.xlsx')
1 loops, best of 3: 6.87 s per loop

Note that xlrd and openpyxl might interpret what is an integer and what is a float slightly differently. For my test data, I needed to add float() to make the outputs comparable:

def UseOpenpyxl(file_name):
    wb = openpyxl.load_workbook(file_name, read_only=True)
    sheet = wb.active
    rows = sheet.rows
    first_row = [float(cell.value) for cell in next(rows)]
    data = []
    for row in rows:
        record = {}
        for key, cell in zip(first_row, row):
            if cell.data_type == 's':
                record[key] = cell.value.strip()
            else:
                record[key] = float(cell.value)
        data.append(record)
    return data

Now, both versions give the same results for my test data:

>>> xlrd_results == openpyxl_results
True
2 of 3
3

You call several times of "sheet.max_column" or "sheet.max_row". Don't do that. Just call it once. If you call it on for loop, each time it will calculate once max_column or max_row.

I modify as below for your reference:

def UseOpenpyxl(file_name):
    wb = openpyxl.load_workbook(file_name, read_only=True)
    sheet = wb.active
    max_col = sheet.max_column
    max_row = sheet.max_row
    first_row = []
    for col in range(1,max_col +1):
        first_row.append(sheet.cell(row=1,column=col).value)
    data = []
    for r in range(2,max_row +1):
        record = {}
        for col in range(max_col):
            if isinstance(sheet.cell(row=r,column=col+1).value, str):
                record[first_row[col]] = sheet.cell(row=r,column=col+1).value.strip()
            else:
                record[first_row[col]] = sheet.cell(row=r,column=col+1).value
        data.append(record)
    return data
🌐
EDUCBA
educba.com › home › software development › software development tutorials › top differences tutorial › xlrd vs openpyxl
Xlrd vs openpyxl | Top Key Differences and Comparisons
February 21, 2023 - Xlrd vs. openpyxl are both used in python. Openpyxl tries to strike a balance between functionality and performance. We prioritized functionality over-optimization by using xlrd and openpyxl.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
StackShare
stackshare.io › stackups › pypi-openpyxl-vs-pypi-xlrd
openpyxl vs xlrd | What are the differences? | StackShare
openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files. xlrd - Library for developers to extract data from Microsoft Excel (tm) spreadsheet files.
🌐
SourceForge
sourceforge.net › software › compare › openpyxl-vs-xlrd
openpyxl vs. xlrd Comparison
Compare openpyxl vs. xlrd using this comparison chart. Compare price, features, and reviews of the software side-by-side to make the best choice for your business.
🌐
openpyxl
openpyxl.readthedocs.io › en › stable › performance.html
Performance — openpyxl 3.1.3 documentation
One major difference between the libraries is that openpyxl’s read-only mode opens a workbook almost immediately making it suitable for multiple processes, this also reduces memory use significantly. xlrd does also not automatically convert dates and times into Python datetimes, though it does annotate cells accordingly but to do this in client code significantly reduces performance.
🌐
openpyxl
openpyxl.readthedocs.io › en › 3.1 › performance.html
Performance — openpyxl 3.1.4 documentation
One major difference between the libraries is that openpyxl’s read-only mode opens a workbook almost immediately making it suitable for multiple processes, this also reduces memory use significantly. xlrd does also not automatically convert dates and times into Python datetimes, though it does annotate cells accordingly but to do this in client code significantly reduces performance.
🌐
Blogger
poquitopicante.blogspot.com › 2013 › 06 › xlrd-vs-openpyxl-round-ii.html
poquito picante: XLRD vs OPENPYXL, Round II
June 3, 2013 - XLRD can open any Excel spreadsheet dating back to like 1995, but OpenPyXL is only for Excel 2007 and newer, which if you didn't know is a zipped XML file. Finally, even though XLRD doesn't let you use the easy Excel cell reference notation, it is generally faster.
🌐
Stack Overflow
stackoverflow.com › questions › 67304720 › python-parsing-excel-files-differences-between-xlrd-and-openpyxl-date-syste
Python - Parsing Excel files / Differences between xlrd and openpyxl (date system and cell value types) - Stack Overflow
Due to the fact that xlrd has deprecated parsing of xlsx files, I am being forced to migrate my excel file parser from xlrd to openpyxl. As of now, I am finding it unclear as to how I would be able...
Find elsewhere
🌐
Slashdot
slashdot.org › software › component libraries › openpyxl vs. xlrd
Compare openpyxl vs. xlrd in 2026
When you create sheets, they are ... a popular choice for many Python developers working with Excel files. The xlrd library is designed for developers looking to extract data from .xls files, which are a type of Microsoft Excel spreadsheet....
🌐
GitHub
github.com › python-excel › xlrd
GitHub - python-excel/xlrd: Please use openpyxl where you can... · GitHub
xlrd is a library for reading data and formatting information from Excel files in the historical .xls format.
Author: python-excel
🌐
GitHub
github.com › pandas-dev › pandas › issues › 28547
Deprecate using `xlrd` engine in favor of openpyxl · Issue #28547 · pandas-dev/pandas
September 20, 2019 - xlrd is unmaintained and the previous maintainer has asked us to move towards openpyxl. xlrd works now, but might have some issues when Python 3.9 or later gets released and changes some elements of the XML parser, as default usage right...
Author: pandas-dev
🌐
Google Groups
groups.google.com › g › python-excel › c › 7zbbcBu4k7o
Reading an Excel .xlsx file is extremely slow with openpyxl
On 7 May 2020, at 10:58, Charlie Clark wrote: > Then there is additional stuff in the file, I assume. The last time I > benchmarked against xlrd openpyxl was faster in read-only, values-only > mode. This somewhat to be expected because xlrd is no longer being > maintained so can't take advantage of any new performance features in > Python.
🌐
Wikibooks
en.wikibooks.org › wiki › Python_Programming › Excel
Python Programming/Excel - Wikibooks, open books for an open world
For working with .xlsx files, there is xlrd for reading, openpyxl for reading and writing, and XlsxWriter and PyExcelerate for writing.
🌐
Medium
medium.com › @waseem3378 › extracting-color-codes-from-excel-files-in-python-with-openpyxl-and-xlrd-18c9bca40d94
Extracting Color Codes from Excel Files in Python with OpenPyXL and XLRD | by Wasim Khan | Medium
September 27, 2024 - OpenPyXL: When working with modern XLSX files where color coding is straightforward. XLRD: For legacy systems or when OpenPyXL fails to detect complex formatting.
🌐
Stack Overflow
stackoverflow.com › questions › 43488871 › openpyxl-pandas-or-xlrd-for-correct-data-representation
python - Openpyxl, Pandas or xlrd for correct data representation? - Stack Overflow
31 Reading Excel file is magnitudes slower using openpyxl compared to xlrd · 0 Read data from excel file for analysis · 7 Fastest way to read .xlsx file with Python · 0 From Python to Excel - Building an excel worksheet · jAMM "Bias-Corrected" bootstrap: BC standard, BC percentile, or BCa?
🌐
Medium
medium.com › @marcschneider_69030 › working-with-excel-xlsx-in-python-2e6e71e990dd
Working with Excel/XLSX in Python | by Marc Schneider | Medium
April 8, 2019 - Can generally handle the use cases ... well with formatting information and charts. xlrd: this package works well with reading and formatting older versions of excel files (.xls)...
🌐
PyXLL
pyxll.com › blog › tools-for-working-with-excel-and-python
Tools for Working with Excel and Python – PyXLL
August 13, 2018 - For more complex tasks because XlsxWriter, OpenPyXL and XLTable all have Pandas integration any of those can also be used to write Pandas DataFrames to Excel. But, for just getting data into Excel using Pandas directly as above is very convenient. ... xlrd and xlwt read and write the old Excel .xls files respectively.
🌐
PyTutorial
pytutorial.com › migrate-from-python-xlrd-to-openpyxl-safely
PyTutorial | Migrate from Python xlrd to openpyxl Safely
November 20, 2025 - For complex projects that work with multiple Excel sheets, openpyxl offers better sheet management. Accessing cell values requires careful migration. xlrd uses row and column indices.
🌐
Quora
quora.com › What-are-Python-libraries-most-useful-for-manipulating-Excel-spreadsheets
What are Python libraries most useful for manipulating Excel spreadsheets? - Quora
Answer (1 of 6): There is and will be only one… it's called Pandas. It comes with its little helper numpy. With Pandas you can achieve pretty much any excel operation you can think of and if you fall in love with it, will pick up lot more statistical operations.