Spire.XLS for Python

16.4.0 · active · verified Thu Apr 16

Spire.XLS for Python is a standalone Excel API designed for processing Excel files (XLS, XLSX, XLSB, XLSM, CSV) within Python applications. It allows developers to create, read, write, convert, and print Excel documents without requiring Microsoft Office. The current version is 16.4.0, and it maintains a regular release cadence with multiple updates annually.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new Excel workbook, write data to cells using A1 notation, auto-fit columns, and save the workbook as an XLSX file. The `Dispose()` method is called to release resources.

from spire.xls import Workbook, SaveFormat

# Create a new workbook
workbook = Workbook()
# Access the first worksheet (0-indexed)
sheet = workbook.Worksheets[0]

# Write data to cells using A1 notation
sheet.Range["A1"].Value = "Hello, Spire.XLS!"
sheet.Range["B1"].Value2 = 12345

# Auto-fit columns
sheet.AllocatedRange.AutoFitColumns()

# Define the output file path
output_file = "output_spire_xls_quickstart.xlsx"

# Save the workbook in XLSX format
workbook.SaveToFile(output_file, SaveFormat.Xlsx)
workbook.Dispose()

print(f"Excel file saved to {output_file}")

view raw JSON →