Create rich .xlsx files from Python · formats · formulas · charts · conditional formatting · verified against XlsxWriter 3.2.x (2026)

XlsxWriter cheat sheet

XlsxWriter writes new Excel .xlsx files with the full feature set: rich cell formats, formulas, charts, conditional formatting, images, tables, sparklines, data validation, and autofilters. Open a Workbook, add worksheets, and write() cells — then close() to produce the file. It is write-only (it cannot read or edit existing files — that's openpyxl), but it's the most complete & fastest writer, with a low-memory mode for huge sheets. Targets XlsxWriter 3.2.x, Python 3.x.

workbook & write formats formulas & tables charts & visuals layout & ecosystem gotcha most common

Verified 2026-08-31 against the official docs at xlsxwriter.readthedocs.io (XlsxWriter 3.2.9, 2026). Pure Python, no dependencies. Write-only — to read/modify existing workbooks use openpyxl. Reached most often via pandas.to_excel(..., engine="xlsxwriter").

Outline

Workbookadd_worksheetwriteclose. Style with add_format; then formulas, conditional formatting, charts, images, and page layout.

Write & format

  1. 1Install & hello
  2. 2Writing cells
  3. 3Formats
  4. 4Rows, columns & size

Formulas & visuals

  1. 5Formulas & tables
  2. 6Conditional formatting
  3. 7Charts
  4. 8Images & widgets

Layout & ecosystem

  1. 9Panes, protection & print
  2. 10Big files & pandas
  3. 11Gotchas & vs openpyxl

Write & Format

The four-step core, cell-writing variants, formats, and sizing.

1Install & hello4 steps
2Writing cellswrite*
3Formatsadd_format
4Rows, columns & sizedimensions

Formulas & Conditional Formatting

Live formulas, Excel tables, and rules that color cells by value.

5Formulas & tableslive values
6Conditional formattingrules by value

Charts & Visuals

Native Excel charts, images, and in-cell widgets.

7Chartsnative Excel charts
8Images & widgetsinsert

Layout & Ecosystem

Freeze panes, protect & print, scale to millions of rows, and pandas.

9Panes, protection & printsheet setup
10Big files & pandasscale
11Gotchas & vs openpyxlchoosing

Worth memorizing

Workbook -> add_worksheet -> write -> closethe lifecycle
write(row, col, val)or write("A1", val) — both work
wb.add_format({...})make once, reuse; belongs to workbook
num_formatcurrency / percent / dates (else serial)
set_column / set_rowwidths & heights; merge_range
write_formulastored, not calculated (cache if needed)
conditional_formatcell / color_scale / data_bar / formula
add_chart + add_series + insert_chartlive Excel charts
freeze_panes / autofilterheaders & filtering
constant_memoryhuge files, write top-to-bottom only
to_excel(engine="xlsxwriter")pandas path
WRITE-ONLYread/edit existing? use openpyxl