Registry / serialization / xlsxwriter

xlsxwriter

JSON →
library3.2.9pypypi✓ verified 28d ago

XlsxWriter is a Python module for creating Excel XLSX files. It supports Python 3.8+ and PyPy3 and uses standard libraries only. It offers comprehensive features for writing, formatting, and customizing Excel spreadsheets, including charts, formulas, data validation, and images. It is actively maintained with regular releases.

pip install XlsxWriter
INSTALL
IMPORT
SIG · XLSXWRITER
X
xlsxwriter
serializationpythonv3.2.9
Install
1.8s avg
Import
109ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.2.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.116s · 19.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.102s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

xlsxwriter
✓ import xlsxwriter
✗ from xlsxwriter import Workbook
While you can import specific classes like Workbook, the standard and most common pattern is to import the top-level 'xlsxwriter' module and access classes via 'xlsxwriter.Workbook', 'xlsxwriter.Worksheet', etc.

This quickstart creates a new Excel file named `hello.xlsx`, adds a single worksheet, writes 'Hello XlsxWriter!' to cell A1, and saves the file.

import xlsxwriter # Create a new Excel file and add a worksheet. workbook = xlsxwriter.Workbook('hello.xlsx') worksheet = workbook.add_worksheet() # Write a simple string to cell A1. worksheet.write('A1', 'Hello XlsxWriter!') # Close the workbook to save the file. workbook.close() print("Created hello.xlsx")
Debug
Known issues
breakingXlsxWriter dropped support for Python 2 after release 2.0. Versions 3.0 and later are exclusively for Python 3.8+.
fix
Ensure you are using Python 3.8 or newer for XlsxWriter versions > 2.0.
affects: <=2.0 (Python 2), >2.0 (Python 3 only)
gotchaXlsxWriter is primarily for *creating* new XLSX files. It cannot read or modify existing Excel files directly. For modifying existing files, users often need to read with a different library (e.g., openpyxl) and then use XlsxWriter to write new content or use it as an engine with pandas.ExcelWriter for appending data.
fix
If modification of existing files is required, consider using `openpyxl` for read/write operations or combine `pandas.ExcelWriter` with `openpyxl` as the engine for appending.
affects: All versions
gotchaFailing to call `workbook.close()` will result in an unsaved or corrupted Excel file.
fix
Always ensure `workbook.close()` is called after all write operations are complete, typically as the last step in your script. Using a `with` statement with `pandas.ExcelWriter` (which uses XlsxWriter as an engine) handles this automatically.
affects: All versions
gotchaXlsxWriter uses zero-indexed rows and columns (e.g., `(0, 0)` for 'A1'), which can be confusing for users accustomed to 1-indexed Excel notation or A1-style strings. However, `worksheet.write()` also accepts A1-style notation.
fix
Be mindful of zero-indexing when using `(row, col)` coordinates. If preferred, use A1-style cell notation (e.g., `'A1'`) with methods like `write()`.
affects: All versions
gotchaWhen integrating with Pandas, `XlsxWriter` is typically specified as the engine for `pd.ExcelWriter(..., engine='xlsxwriter')`. In this scenario, you usually don't need to explicitly import `xlsxwriter` at the top of your script for basic dataframe output.
fix
Understand that `pandas.ExcelWriter` handles the interaction with XlsxWriter when `engine='xlsxwriter'` is set. Direct `xlsxwriter` imports are primarily for standalone use or for advanced customizations that require direct access to XlsxWriter objects (like `workbook = writer.book`).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'xlsxwriter'
The XlsxWriter library is not installed in your Python environment.
fix
pip install XlsxWriter
AttributeError: 'Workbook' object has no attribute 'add_worksheet'
You are calling a misspelled or non-existent method on the Workbook object; the correct method name is add_worksheet().
fix
worksheet = workbook.add_worksheet('Sheet1')
TypeError: write() missing 2 required positional arguments: 'col' and 'token'
The write() method requires at least three positional arguments: the row, the column, and the value to write.
fix
worksheet.write(0, 0, 'Hello World')
ValueError: Invalid argument to merge_range(): 'first_row' must be <= 'last_row' and 'first_col' must be <= 'last_col'.
The merge_range() method was called with invalid coordinates where the starting row or column is greater than the ending row or column.
fix
worksheet.merge_range(0, 0, 0, 2, 'Merged Cells')
Upgrade
Version history
3.2.9latest on PyPI · released Sep 16, 2025
Audit
Dependencies
pandasoptionalCommonly used for data manipulation and then writing DataFrames to Excel files via XlsxWriter as an engine.
Agent activity
50 hits · last 30 days
node
40
OpenAI (training)
1
Resources
xlsxwriter — pip install xlsxwriter · libregistry