Fast XLSX Reader

1.1.3 · active · verified Thu Apr 16

Pyxlsx is a fast and memory-efficient Python library designed for reading data from XLSX (Excel) files. It focuses on parsing core data, shared strings, and basic styling, making it suitable for high-performance data extraction. The current stable version is 1.1.3, and releases are typically made for bug fixes and minor improvements as needed.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple XLSX file using `openpyxl` and then read its contents using `pyxlsx`. It shows basic row iteration and includes cleanup.

import openpyxl
import os
from pyxlsx import Reader

# Create a dummy XLSX file for demonstration
file_path = "example.xlsx"
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet['A1'] = "Name"
sheet['B1'] = "Age"
sheet['A2'] = "Alice"
sheet['B2'] = 30
sheet['A3'] = "Bob"
sheet['B3'] = 24
workbook.save(file_path)

print(f"Created dummy file: {file_path}")

# Use pyxlsx to read the file
try:
    reader = Reader(file_path)
    # pyxlsx iterators are one-pass; convert to list if you need to iterate multiple times
    rows_data = list(reader.rows())
    
    if rows_data:
        print("Header row:", rows_data[0])
        print("Data rows:")
        for row in rows_data[1:]:
            print(row)
    else:
        print("No data found in the file.")

except FileNotFoundError:
    print(f"Error: The file {file_path} was not found. Please ensure it exists.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(file_path):
        os.remove(file_path)
        print(f"Cleaned up dummy file: {file_path}")

view raw JSON →