xlwt

1.3.0 · deprecated · verified Thu Apr 09

xlwt is a Python library for generating spreadsheet files compatible with MS Excel 97/2000/XP/2003 XLS files. It operates on any platform and supports Python 2.6, 2.7, and 3.3+. The current version is 1.3.0, released in 2017, and the project is effectively feature-frozen and no longer actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new Excel .xls workbook, add a sheet, write data to cells, apply basic styling, and save the file. Remember that xlwt only produces the older .xls format.

import xlwt

# Create a new workbook
workbook = xlwt.Workbook()

# Add a sheet
sheet = workbook.add_sheet('Sheet1')

# Write some data to cells
sheet.write(0, 0, 'Name')
sheet.write(0, 1, 'Age')
sheet.write(1, 0, 'Alice')
sheet.write(1, 1, 30)

# Add some styling
style = xlwt.easyxf('font: bold on; align: horiz center')
sheet.write(2, 0, 'Bob', style)
sheet.write(2, 1, 24, style)

# Save the workbook
file_path = 'example.xls'
try:
    workbook.save(file_path)
    print(f'Successfully created {file_path}')
except Exception as e:
    print(f'Error saving workbook: {e}')

view raw JSON →