Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python Excel libraries read and write spreadsheet files from code, most of them without Excel installed. These libraries automate the reports, data imports, and exports that teams exchange as Excel workbooks.
Popularity
openpyxl has the most installs, while XlsxWriter has the most GitHub stars.
openpyxl reads and writes Excel workbooks in the Office Open XML formats, .xlsx, .xlsm, .xltx, and .xltm, without Excel installed. Workbook creates a new file, and ws.append adds a row to a worksheet. Cells are read and set by coordinate, with Python values such as dates converted to Excel types automatically. Unlike XlsxWriter, openpyxl also opens existing workbooks and changes their sheets, cells, and formulas.
Downloads / mo
283.0M
Last release
3.1.5, Jun 2024
License
MIT
Strengths
Edits existing workbooks.Opens a workbook so code can change its sheets, cells, and formulas.
Handles large files.Read-only and write-only modes keep memory low, without styles.
Limitations
Memory per cell.Each cell takes one to two kilobytes. Read-only and write-only modes cut memory use on large sheets.
Can drop content on save.Saving an opened workbook loses any part openpyxl doesn't read.
No XML attack guard by default.Untrusted files need the defusedxml package installed, which openpyxl then uses to block billion laughs and quadratic blowup attacks.
from openpyxl import Workbook
wb = Workbook()
# grab the active worksheetws = wb.active
# Data can be assigned directly to cellsws['A1'] = 42
# Rows can also be appendedws.append([1, 2, 3])
# Save the filewb.save("sample.xlsx")
def read_xlsx_file_from_attached_file(file_url=None, fcontent=None, filepath=None, *, read_only=False):
if file_url:
_file = frappe.get_doc("File", {"file_url": file_url})
# read through the File, so a file on another storage driver works too filename = BytesIO(_file.get_content())
elif fcontent:
filename = BytesIO(fcontent)
elif filepath:
filename = filepath
else:
return
from openpyxl import load_workbook
rows = []
wb1 = load_workbook(filename=filename, data_only=True, read_only=read_only)
ws1 = wb1.active
for row in ws1.iter_rows():
rows.append([cell.value for cell in row])
if read_only:
wb1.close()
return rows
def export_book(cls, databook, freeze_panes=True, invalid_char_subst="-",
escape=False, column_width=None):
"""Returns XLSX representation of DataBook.
See export_set().
"""
wb = Workbook()
for sheet in wb.worksheets:
wb.remove(sheet)
for i, dset in enumerate(databook._datasets):
ws = wb.create_sheet()
ws.title = (
safe_xlsx_sheet_title(dset.title, invalid_char_subst)
if dset.title else f"Sheet{i}"
)
cls.dset_sheet(dset, ws, freeze_panes=freeze_panes, escape=escape)
cls._adapt_column_width(ws, column_width)
stream = BytesIO()
wb.save(stream)
return stream.getvalue()
XlsxWriter
XlsxWriter writes new Excel .xlsx files using only the Python standard library. A Workbook contains worksheets created with add_worksheet. The write method places text, numbers, formulas, or links into cells, with styles made by add_format. Charts, images, conditional formatting, data validation, and macros are supported, along with a memory optimization mode for large files. pandas and Polars can both use XlsxWriter to save DataFrames.
Downloads / mo
95.4M
Stars
4.0K
Last release
3.3.1, Oct 2026
License
BSD-2-Clause
Strengths
Clean files for Excel.Writes text, numbers, formulas, and links to sheets Excel opens cleanly.
Native charts and images.Adds Excel charts, images, and conditional formatting.
Limitations
New files only.Can't open or edit an existing workbook.
import xlsxwriter
# Create an new Excel file and add a worksheet.workbook = xlsxwriter.Workbook("demo.xlsx")
worksheet = workbook.add_worksheet()
# Add a bold format to use to highlight cells.bold = workbook.add_format({"bold": True})
# Write some simple text.worksheet.write("A1", "Hello")
# Text with formatting.worksheet.write("A2", "World", bold)
workbook.close()
def _write_cells(
self,
cells,
sheet_name: str | None = None,
startrow: int = 0,
startcol: int = 0,
freeze_panes: tuple[int, int] | None = None,
autofilter_range: str | None = None,
) -> None:
sheet_name = self._get_sheet_name(sheet_name)
wks = self.book.get_worksheet_by_name(sheet_name)
if wks is None:
wks = self.book.add_worksheet(sheet_name)
style_dict = {"null": None}
if validate_freeze_panes(freeze_panes):
wks.freeze_panes(*(freeze_panes))
for cell in cells:
val, fmt = self._value_with_fmt(cell.val)
# ... if stylekey in style_dict:
style = style_dict[stylekey]
else:
style = self.book.add_format(_XlsxStyler.convert(cell.style, fmt))
style_dict[stylekey] = style
if cell.mergestart is not None and cell.mergeend is not None:
wks.merge_range(
startrow + cell.row,
startcol + cell.col,
startrow + cell.mergestart,
startcol + cell.mergeend,
val,
style,
)
else:
wks.write(startrow + cell.row, startcol + cell.col, val, style)
if autofilter_range:
wks.autofilter(autofilter_range)
xlrd
xlrd reads data and formatting from Excel files in the older .xls format and no other format. open_workbook returns a book, sheet_by_index returns a sheet, and cell_value reads one cell. Formula results come back as values. Each sheet exposes cell comments through cell_note_map and hyperlinks through hyperlink_map. Newer formats need another library, such as openpyxl for .xlsx.
Downloads / mo
67.0M
Stars
2.2K
Last release
2.0.2, Jun 2025
License
BSD-3-Clause
Strengths
Reads old .xls files.The standard reader for .xls, with no dependencies.
Built into pandas.pandas.read_excel uses xlrd for .xls files automatically.
import xlrd
book = xlrd.open_workbook("myfile.xls")
print("The number of worksheets is {0}".format(book.nsheets))
print("Worksheet name(s): {0}".format(book.sheet_names()))
sh = book.sheet_by_index(0)
print("{0} {1} {2}".format(sh.name, sh.nrows, sh.ncols))
print("Cell D30 is {0}".format(sh.cell_value(rowx=29, colx=3)))
for rx in range(sh.nrows):
print(sh.row(rx))
def load_workbook(self, filepath_or_buffer, engine_kwargs) -> Book:
from xlrd import open_workbook
if hasattr(filepath_or_buffer, "read"):
data = filepath_or_buffer.read()
return open_workbook(file_contents=data, **engine_kwargs)
else:
return open_workbook(filepath_or_buffer, **engine_kwargs)
pyxlsb
pyxlsb reads Excel binary workbooks, the .xlsb format. open_workbook opens a file, get_sheet picks a sheet by name or by position counting from one, and rows iterates over the sheet as lists of cells. Dates arrive as floats, which convert_date turns into datetime values. The README describes the library as limited but enough for basic data extraction.
Downloads / mo
8.6M
Stars
96
Last release
1.0.10, Oct 2022
License
LGPL-3.0
Strengths
Reads big .xlsb files row by row.Returns rows as it reads them, so large files stay manageable.
Built into pandas.pandas.read_excel uses pyxlsb for .xlsb files automatically.
Limitations
Reads rows only.Can't write files or read formatting.
Errors come back as codes.Cells like #DIV/0! return as hex codes to map back by hand.
Dates come back as numbers.Each date needs convert_date() to become a datetime.
def get_sheet_data(
self,
sheet: Worksheet,
file_rows_needed: int | None = None,
) -> list[list[Scalar]]:
data: list[list[Scalar]] = []
previous_row_number = -1
# When sparse=True the rows can have different lengths and empty rows are # not returned. The cells are namedtuples of row, col, value (r, c, v). for row in sheet.rows(sparse=True):
row_number = row[0].r
converted_row = [self._convert_cell(cell) for cell in row]
while converted_row and converted_row[-1] == "":
# trim trailing empty elements converted_row.pop()
if converted_row:
data.extend([[]] * (row_number - previous_row_number - 1))
data.append(converted_row)
previous_row_number = row_number
if file_rows_needed is not None and len(data) >= file_rows_needed:
break
if data:
# extend rows to max_width max_width = max(len(data_row) for data_row in data)
if min(len(data_row) for data_row in data) < max_width:
empty_cell: list[Scalar] = [""]
data = [
data_row + (max_width - len(data_row)) * empty_cell
for data_row in data
]
return data
python-calamine
python-calamine is a Python binding for calamine, a Rust library for Excel and OpenDocument spreadsheets: .xlsx, .xlsm, .xlsb, .xls, and .ods. CalamineWorkbook.from_path opens a file, and a sheet's to_python method returns its cells as a list of rows. Blank rows and columns before the data are skipped unless skip_empty_area is false. pandas reads through python-calamine with engine="calamine", so one engine covers formats that otherwise need openpyxl, xlrd, and pyxlsb.
Downloads / mo
6.7M
Stars
510
Last release
0.9.1, Nov 2026
License
MIT
Strengths
Fastest reader.Reads .xlsx, .xlsm, .xlsb, .xls, and .ods faster than the others here.
Works inside pandas.pandas reads through it with engine="calamine".
Limitations
Read-only.Writing files needs another library, such as openpyxl.
Whole numbers become floats.IDs and counts come back as floats, such as 0.0.
def calamaine_excel_engine(file,cutoff):
# # Read from S3 s3 = boto3.client('s3')
match = re.match("s3://(.+?)/(.+)", file)
if match:
bucket_name = match.group(1)
key = match.group(2)
obj = s3.get_object(Bucket=bucket_name, Key=key)
# Read Excel file from S3 into a buffer xlsx_buffer = io.BytesIO(obj['Body'].read())
xlsx_buffer.seek(0)
all_sheets_string = ""
# Load the Excel file workbook = CalamineWorkbook.from_filelike(xlsx_buffer)
# Iterate over each sheet in the workbook for sheet_name in workbook.sheet_names:
# Get the sheet by name sheet = workbook.get_sheet_by_name(sheet_name)
df = pd.DataFrame(sheet.to_python(skip_empty_area=False))
df = df.map(strip_newline)
preview_note = ""
if cutoff and len(df) > cutoff:
preview_note = (f"\n[PREVIEW: first {cutoff} of {len(df)} rows. The "
"data-analysis tool has access to the complete file.]\n")
df = df.iloc[:cutoff]
# print(df) tabb = df.to_csv(sep=CSV_SEPERATOR, index=False, header=0)
all_sheets_string += f'<{sheet_name}>\n{tabb}{preview_note}\n</{sheet_name}>\n'
return all_sheets_string
else:
raise Exception(f"{file} not formatted as an S3 path")
def get_sheet_data(
self, sheet: CalamineSheet, file_rows_needed: int | None = None
) -> list[list[Scalar | NaTType | time]]:
def _convert_cell(value: _CellValue) -> Scalar | NaTType | time:
if isinstance(value, float):
# GH#54564 - is_integer() returns False for NaN/Inf, # so this safely avoids int() on non-finite values if value.is_integer():
return int(value)
return value
elif isinstance(value, (datetime, timedelta)):
# Return as-is to match openpyxl behavior (GH#59186) return value
elif isinstance(value, date):
# Convert date to datetime to match openpyxl behavior (GH#59186) return datetime(value.year, value.month, value.day)
elif isinstance(value, time):
return value
return value
rows: list[list[_CellValue]] = sheet.to_python(
skip_empty_area=False, nrows=file_rows_needed
)
data = [[_convert_cell(cell) for cell in row] for row in rows]
return data
pyexcel-io
pyexcel-io reads and writes spreadsheet data through one pair of functions, get_data and save_data. The same functions move data into and out of Django and SQLAlchemy databases. CSV and TSV work without extras. Excel and OpenDocument formats each come from a plugin package, such as pyexcel-xlsx, built on openpyxl, or pyexcel-xls, built on xlrd. When two installed plugins handle the same format, the library argument picks one per call.
Downloads / mo
1.4M
Stars
58
Last release
0.6.8, Jun 2026
License
BSD-3-Clause
Strengths
One API for every format.The same calls read and write CSV, xls, xlsx, and ods.
Loads into databases.Moves sheet data into and out of Django and SQLAlchemy.
Limitations
Values only.No fonts, colors, charts, or password-protected files.
Plugin per format.xls, xlsx, and ods each need a separate plugin package.
xlwings controls a running copy of Excel from Python on Windows and macOS, so Excel has to be installed. xw.Book opens or connects to a workbook, wb.sheets returns a sheet, and assigning to a range's value writes cells. Converters move NumPy arrays and pandas DataFrames in both directions. In the other direction, macros written in Python replace VBA, and user-defined functions run in cells on Windows. Excel itself recalculates formulas and saves the file.
Downloads / mo
578.0K
Stars
3.4K
Last release
0.37.8, Oct 2026
License
BSD-3-Clause
Strengths
DataFrames in and out of Excel.Moves pandas DataFrames to Excel ranges and back.
Replaces VBA.Writes Excel macros and custom functions in Python.
Formulas recalculate.Excel itself saves the file, so formulas update.
Limitations
Needs Excel installed.Runs only on a desktop with Excel, so server jobs are fragile.
Some features are paid.xlwings Server, Reports, and Reader are part of xlwings PRO, which needs a paid license for commercial use.
def refresh_dropdown() -> None:
"""Refreshes the dropdown on the Tracker tab with the content of
the packages table.
"""
# Excel objects book = xw.Book.caller()
dropdown_sheet = book.sheets["Dropdown"]
tracker_sheet = book.sheets["Tracker"]
dropdown_content_cell = dropdown_sheet["dropdown_content"]
# Clear the current value in the dropdown tracker_sheet["package_selection"].clear_contents()
# Delete the content of the Excel table and repopulate it # with the values from the packages database table if dropdown_content_cell.value:
dropdown_content_cell.delete()
packages = database.get_packages()
dropdown_content_cell.options(header=False, index=False).value = packages
def show_history() -> None:
"""Shows the latest release and plots the release history
(number of releases per year)
"""
# Excel objects book = xw.Book.caller()
tracker_sheet = book.sheets["Tracker"]
package_name = tracker_sheet["package_selection"].value
feedback_cell = tracker_sheet["package_selection"].offset(column_offset=1)
picture_cell = tracker_sheet["latest_release"].offset(row_offset=2)
latest_release_cell = tracker_sheet["latest_release"]
# ... # Clear output cells and picture feedback_cell.clear_contents()
tracker_sheet["latest_release"].clear_contents()
if "releases_per_year" in tracker_sheet.pictures:
tracker_sheet.pictures["releases_per_year"].delete()
# ... # Plot fig = create_releases_chart(releases, package_name)
latest_date = releases.index.max()
latest_version = releases.loc[latest_date, "version"]
latest_release_cell.value = f"{latest_version} ({latest_date:%B %d, %Y})"
tracker_sheet.pictures.add(
fig, name="releases_per_year", top=picture_cell.top, left=picture_cell.left
)
PyExcelerate
PyExcelerate writes .xlsx files with an emphasis on speed. new_sheet takes a two-dimensional list of values at once, and range writes a block of cells. Single cells, formulas, dates, merged cells, and styles are supported too, though each step away from bulk values runs slower. In the README's benchmark, bulk values write faster than with XlsxWriter or openpyxl.
Downloads / mo
400.7K
Stars
559
Last release
0.13.0, May 2025
License
BSD-2-Clause
Strengths
Fast bulk writes.Writes 1000 rows by 100 columns of values in 0.47 seconds.
Limitations
Styles slow writes.In the README benchmark, a styled sheet of 1000 rows by 100 columns takes 2.40 to 6.15 seconds, against 0.47 for plain values.
Writes only.Reading files and conditional formatting need another library.
def export_xlsx(request):
products = Product.objects.all()
data = [(product.title, product.price) for product in products]
data.insert(0, ('title', 'price'))
wb = Workbook()
wb.new_sheet("sheet name", data=data)
wb.save("/tmp/products_out.xlsx")
return redirect('product:product_list')
FAQ
It depends on the job: openpyxl edits existing .xlsx workbooks and has 283.0M downloads a month, XlsxWriter builds new formatted files, python-calamine reads fastest, and xlwings drives Excel itself.
pandas.read_excel() reads a sheet into a DataFrame and picks a reader by file type: openpyxl for .xlsx, xlrd for .xls, and pyxlsb for .xlsb. Pass engine="calamine" to read through python-calamine instead, which is faster. pandas plans to make calamine the default .xlsx reader.
No. openpyxl keeps the pivot tables in an existing file when it saves, and can change a pivot table's range or refresh setting, but it can't create a new one. xlwings can build one, because it drives a running copy of Excel.
openpyxl reads, edits, and writes .xlsx files. XlsxWriter only writes new files, but it has the richer formatting options, native charts, and a constant_memory mode for very large exports. Use openpyxl to change a workbook that already exists, and XlsxWriter to build a report from scratch.
pandas shapes the data and openpyxl handles the file. pandas.read_excel() and DataFrame.to_excel() call openpyxl or XlsxWriter underneath. Use openpyxl directly for cell formatting, formulas, or editing a workbook in place.
Yes. xlwings lets Excel call Python functions from cells and replaces VBA macros with Python code. It needs a desktop copy of Excel on Windows or macOS.
openpyxl is a Python library that reads and writes Excel .xlsx and .xlsm files. It can open an existing workbook, change its sheets, cells, and formulas, and save it. pandas uses it as the default .xlsx reader.
For coding agents
Found your Excel library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.