or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-features.mdcharts.mddata-writing.mdformatting.mdindex.mdpage-setup.mdutilities.mdworkbook.md
tile.json

tessl/pypi-xlsxwriter

A Python module for creating Excel XLSX files.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/xlsxwriter@3.2.x

To install, run

npx @tessl/cli install tessl/pypi-xlsxwriter@3.2.0

index.mddocs/

XlsxWriter

A comprehensive Python library for creating Excel 2007+ XLSX files with full formatting capabilities. XlsxWriter provides extensive functionality for writing text, numbers, formulas, and hyperlinks to multiple worksheets with support for advanced Excel features including charts, merged cells, conditional formatting, data validation, autofilters, images, and macros.

Package Information

  • Package Name: xlsxwriter
  • Language: Python
  • Installation: pip install xlsxwriter
  • Python Version: 3.8+ and PyPy3
  • Dependencies: Standard library only

Core Imports

import xlsxwriter

Most common pattern:

import xlsxwriter

# Create workbook and worksheet
workbook = xlsxwriter.Workbook('output.xlsx')
worksheet = workbook.add_worksheet()

Basic Usage

import xlsxwriter

# Create a workbook and add a worksheet
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()

# Write some data with formatting
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'Hello', bold)
worksheet.write('B1', 'World')
worksheet.write('A2', 123)
worksheet.write('B2', 456.789)

# Add a formula
worksheet.write('A3', '=SUM(A2:B2)')

# Insert a chart
chart = workbook.add_chart({'type': 'column'})
chart.add_series({
    'categories': '=Sheet1!A1:B1',
    'values': '=Sheet1!A2:B2',
})
worksheet.insert_chart('D2', chart)

# Close the workbook
workbook.close()

Architecture

XlsxWriter uses a hierarchical structure for building Excel files:

  • Workbook: Top-level container managing worksheets, formats, and global settings
  • Worksheet: Individual sheet containing data, formatting, and objects like charts/images
  • Format: Styling objects for fonts, colors, borders, alignment, and number formatting
  • Chart: Visualization objects with various types (column, line, pie, etc.)
  • Utilities: Helper functions for Excel coordinate conversions and reference handling

The library provides 100% compatibility with Excel XLSX format and includes memory optimization for large files, integration with Pandas/Polars, and support for advanced Excel features like macros and VBA projects.

Capabilities

Workbook Management

Core workbook functionality for creating, configuring, and managing Excel files including worksheet creation, format definition, chart creation, and global workbook settings.

class Workbook:
    def __init__(self, filename, options=None): ...
    def add_worksheet(self, name=None, worksheet_class=None): ...
    def add_format(self, properties=None): ...
    def add_chart(self, options): ...
    def close(self): ...
    def set_properties(self, properties): ...

Workbook Management

Data Writing and Cell Operations

Comprehensive data writing capabilities including support for all Excel data types, formulas, hyperlinks, rich text, and specialized writing methods for rows, columns, and cell ranges.

def write(row, col, *args): ...
def write_string(row, col, string, cell_format=None): ...
def write_number(row, col, number, cell_format=None): ...
def write_formula(row, col, formula, cell_format=None, value=0): ...
def write_datetime(row, col, date, cell_format=None): ...
def write_url(row, col, url, cell_format=None, string=None, tip=None): ...

Data Writing

Formatting and Styling

Complete cell formatting system including fonts, colors, borders, alignment, number formats, patterns, and fill options with support for conditional formatting and cell protection.

class Format:
    def set_font_name(self, font_name): ...
    def set_font_size(self, font_size=11): ...
    def set_bold(self, bold=True): ...
    def set_align(self, alignment): ...
    def set_bg_color(self, bg_color): ...
    def set_border(self, style=1): ...

Formatting and Styling

Charts and Visualization

Comprehensive charting system supporting all major Excel chart types including column, line, pie, scatter, area, bar, radar, doughnut, and stock charts with full customization options.

class Chart:
    def add_series(self, options=None): ...
    def set_title(self, options=None): ...
    def set_x_axis(self, options): ...
    def set_y_axis(self, options): ...
    def set_legend(self, options): ...

Charts and Visualization

Advanced Features

Advanced Excel functionality including data validation, conditional formatting, autofilters, tables, sparklines, images, textboxes, comments, and worksheet protection.

def data_validation(first_row, first_col, last_row, last_col, options=None): ...
def conditional_format(first_row, first_col, last_row, last_col, options=None): ...
def add_table(first_row, first_col, last_row, last_col, options=None): ...
def insert_image(row, col, source, options=None): ...
def autofilter(first_row, first_col, last_row, last_col): ...

Advanced Features

Page Setup and Printing

Complete page setup and print configuration including orientation, margins, headers/footers, page breaks, print areas, scaling options, and paper size settings.

def set_landscape(): ...
def set_margins(left=0.7, right=0.7, top=0.75, bottom=0.75): ...
def set_header(header="", options=None, margin=None): ...
def print_area(first_row, first_col, last_row, last_col): ...
def fit_to_pages(width, height): ...

Page Setup and Printing

Utility Functions and Helpers

Essential utility functions for Excel coordinate conversions, cell reference handling, range creation, and worksheet name management.

def xl_rowcol_to_cell(row, col, row_abs=False, col_abs=False): ...
def xl_cell_to_rowcol(cell_str): ...
def xl_range(first_row, first_col, last_row, last_col): ...
def quote_sheetname(sheetname): ...

Utility Functions

Types

class XlsxWriterException(Exception):
    """Base exception for XlsxWriter."""

class XlsxInputError(XlsxWriterException):
    """Base exception for all input data related errors."""

class XlsxFileError(XlsxWriterException):
    """Base exception for all file related errors."""