pyexcel-xlsx: XLSX/XLSM Handler for pyexcel
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
- breaking Version 0.6.0 dropped support for Python versions lower than 3.6. Additionally, it introduced 'new style plugins' aligned with pyexcel-io v0.6.2+, which means older `pyexcel-io` plugins are incompatible with this version.
- gotcha When using `pyexcel` as the main interface (e.g., `pyexcel.get_sheet()` or `pyexcel.save_as()`), `pyexcel-xlsx` is auto-loaded. Explicitly importing `pyexcel_xlsx` is generally not needed and can lead to confusion if standalone functions are used alongside the unified API.
- gotcha The library primarily focuses on data processing. Features like fonts, colors, charts, or other styling elements within XLSX/XLSM files are not supported.
- gotcha pyexcel-xlsx does not support reading or writing password-protected XLSX/XLSM files.
- gotcha The `auto_detect_int` flag, commonly found in other Excel libraries, has no effect when using `pyexcel-xlsx`. This is because `openpyxl`, its underlying dependency, detects integers by default in Python 3.
Install
-
pip install pyexcel-xlsx
Imports
- get_data
from pyexcel_xlsx import get_data
- save_data
from pyexcel_xlsx import save_data
- pyexcel
import pyexcel as pe
Quickstart
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}")