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 XlsxWriterVerified import paths — ran on the pinned version, not inferred.
This quickstart creates a new Excel file named `hello.xlsx`, adds a single worksheet, writes 'Hello XlsxWriter!' to cell A1, and saves the file.
Ensure you are using Python 3.8 or newer for XlsxWriter versions > 2.0.
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.
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.
Be mindful of zero-indexing when using `(row, col)` coordinates. If preferred, use A1-style cell notation (e.g., `'A1'`) with methods like `write()`.
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`).
pip install XlsxWriter
worksheet = workbook.add_worksheet('Sheet1')worksheet.write(0, 0, 'Hello World')
worksheet.merge_range(0, 0, 0, 2, 'Merged Cells')