PyExcel

0.7.4 · active · verified Fri Apr 10

PyExcel is a wrapper library that provides a unified API to read, manipulate, and write data in various Excel formats such as CSV, XLS, XLSX, and ODS. It focuses purely on data processing, enabling easy conversion of Excel data into Python arrays or dictionaries and vice versa, without supporting features like fonts, colors, or charts. The library is actively maintained, with frequent minor releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to write a Python dictionary to a multi-sheet Excel file and then read it back into a sheet object and a book dictionary. It assumes the necessary format-specific plugins (like `pyexcel-xlsx`) are installed.

import pyexcel
from collections import OrderedDict

# --- Writing data to an Excel file (e.g., 'your_file.xlsx') ---
data = OrderedDict()
data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
data.update({"Sheet 2": [['a', 'b', 'c'], ['d', 'e', 'f']]})

# Ensure pyexcel-xlsx is installed: pip install pyexcel-xlsx
pyexcel.save_book_as(bookdict=data, dest_file_name="your_file.xlsx")
print("Data written to your_file.xlsx")

# --- Reading data from an Excel file ---
# Ensure pyexcel-xlsx is installed: pip install pyexcel-xlsx
sheet = pyexcel.get_sheet(file_name="your_file.xlsx")
print(f"Content of Sheet 1 (as array): {sheet.array}")

# You can also get the whole book as a dictionary of sheets
book_dict = pyexcel.get_book_dict(file_name="your_file.xlsx")
print(f"Content of the entire book: {book_dict}")

view raw JSON →