{"id":598,"library":"xlsxwriter","title":"XlsxWriter","description":"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.","status":"active","version":"3.2.9","language":"python","source_language":"en","source_url":"https://github.com/jmcnamara/XlsxWriter","tags":["excel","xlsx","spreadsheet","report","automation","data-export"],"install":[{"cmd":"pip install XlsxWriter","lang":"bash","label":"Install XlsxWriter"}],"dependencies":[{"reason":"Commonly used for data manipulation and then writing DataFrames to Excel files via XlsxWriter as an engine.","package":"pandas","optional":true}],"imports":[{"note":"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.","wrong":"from xlsxwriter import Workbook","symbol":"xlsxwriter","correct":"import xlsxwriter"}],"quickstart":{"code":"import xlsxwriter\n\n# Create a new Excel file and add a worksheet.\nworkbook = xlsxwriter.Workbook('hello.xlsx')\nworksheet = workbook.add_worksheet()\n\n# Write a simple string to cell A1.\nworksheet.write('A1', 'Hello XlsxWriter!')\n\n# Close the workbook to save the file.\nworkbook.close()\nprint(\"Created hello.xlsx\")","lang":"python","description":"This quickstart creates a new Excel file named `hello.xlsx`, adds a single worksheet, writes 'Hello XlsxWriter!' to cell A1, and saves the file."},"warnings":[{"fix":"Ensure you are using Python 3.8 or newer for XlsxWriter versions > 2.0.","message":"XlsxWriter dropped support for Python 2 after release 2.0. Versions 3.0 and later are exclusively for Python 3.8+.","severity":"breaking","affected_versions":"<=2.0 (Python 2), >2.0 (Python 3 only)"},{"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.","message":"XlsxWriter 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Failing to call `workbook.close()` will result in an unsaved or corrupted Excel file.","severity":"gotcha","affected_versions":"All versions"},{"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()`.","message":"XlsxWriter 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.","severity":"gotcha","affected_versions":"All versions"},{"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`).","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T16:25:57.573Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install XlsxWriter","cause":"The XlsxWriter library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'xlsxwriter'"},{"fix":"worksheet = workbook.add_worksheet('Sheet1')","cause":"You are calling a misspelled or non-existent method on the Workbook object; the correct method name is add_worksheet().","error":"AttributeError: 'Workbook' object has no attribute 'add_worksheet'"},{"fix":"worksheet.write(0, 0, 'Hello World')","cause":"The write() method requires at least three positional arguments: the row, the column, and the value to write.","error":"TypeError: write() missing 2 required positional arguments: 'col' and 'token'"},{"fix":"worksheet.merge_range(0, 0, 0, 2, 'Merged Cells')","cause":"The merge_range() method was called with invalid coordinates where the starting row or column is greater than the ending row or column.","error":"ValueError: Invalid argument to merge_range(): 'first_row' must be <= 'last_row' and 'first_col' must be <= 'last_col'."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.2.9","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4,"disk_size":"19.2M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4,"disk_size":"19.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.06,"mem_mb":4,"disk_size":"20M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.06,"mem_mb":4,"disk_size":"20M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":4.6,"disk_size":"21.4M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.18,"mem_mb":4.6,"disk_size":"21.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.7,"import_time_s":0.13,"mem_mb":4.6,"disk_size":"22M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4.6,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":4.5,"disk_size":"13.2M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4.5,"disk_size":"13.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.14,"mem_mb":4.5,"disk_size":"14M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":4.5,"disk_size":"14M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.11,"mem_mb":4.5,"disk_size":"13.0M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":4.5,"disk_size":"12.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.12,"mem_mb":4.5,"disk_size":"13M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":4.5,"disk_size":"13M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":4.2,"disk_size":"18.7M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.2,"disk_size":"18.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.9,"import_time_s":0.08,"mem_mb":4.2,"disk_size":"19M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.2,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}