PyExcelerate
PyExcelerate is an accelerated Python library designed for quickly writing Excel XLSX files, with an emphasis on performance and efficient memory usage. It is currently at version 0.13.0 and supports both Python 2.7 and various Python 3 versions, though a strict release cadence is not always observed.
Warnings
- gotcha PyExcelerate can consume a significant amount of memory when writing extremely large datasets, as it does not inherently offer a constant-memory mode like some other libraries. Users dealing with datasets of millions of rows might encounter memory exhaustion.
- gotcha Applying styles cell-by-cell can introduce substantial performance overhead, potentially slowing down execution by up to 10 times. PyExcelerate is optimized for speed when writing raw data.
- gotcha Writing large dataframes primarily containing strings can occasionally result in corrupted or invalid XLSX files that Excel cannot open correctly. This issue seems to be more prevalent with specific data characteristics and large file sizes.
- gotcha When writing multiple sheets to a single workbook, ensure that the `Workbook()` object is instantiated only once. Repeatedly calling `wb = Workbook()` will create a new, empty workbook each time, overwriting any previously added sheets when `save()` is called.
Install
-
pip install pyexcelerate
Imports
- Workbook
from pyexcelerate import Workbook
Quickstart
from pyexcelerate import Workbook
import os
data = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
] # data is a 2D array
wb = Workbook()
ws = wb.new_sheet("MySheet", data=data)
# Optional: Set column widths or row heights
ws.set_col_style(1, ws.style.font.bold)
ws.set_row_style(1, ws.style.font.italic)
ws.cell(1,1).value = "Bold Italic"
file_path = "output.xlsx"
wb.save(file_path)
print(f"Workbook saved to {os.path.abspath(file_path)}")