pyexcel-xlsx: XLSX/XLSM Handler for pyexcel

0.6.1 · active · verified Sat Apr 11

pyexcel-xlsx is a wrapper library designed to read, manipulate, and write data in XLSX and XLSM formats by leveraging `openpyxl`. It functions as a plugin for the `pyexcel` ecosystem, offering a unified API for handling various Excel file types. The library is actively maintained with regular updates and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to write an `OrderedDict` to an XLSX file and then read it back using `pyexcel`'s unified API, which automatically utilizes `pyexcel-xlsx` for the XLSX format. It covers both saving and retrieving data from multi-sheet Excel files.

import pyexcel as pe
from collections import OrderedDict
import os

# Create some data for an Excel sheet
data = OrderedDict()
data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
data.update({"Sheet 2": [["A", "B", "C"], [7, 8, 9]]})

file_name = "my_excel_file.xlsx"

# Save data to an XLSX file using pyexcel's unified API
pe.save_as(adict=data, dest_file_name=file_name)
print(f"Data successfully saved to {file_name}")

# Read data from the XLSX file
book = pe.get_book(file_name=file_name)

print(f"\nData read from {file_name}:")
for sheet_name in book.sheet_names():
    sheet = book.sheet_by_name(sheet_name)
    print(f"Sheet Name: {sheet_name}")
    for row in sheet:
        print(row)

# Clean up the created file
os.remove(file_name)
print(f"\nCleaned up {file_name}")

view raw JSON →