Skip to main content

python-spreadsheet-reader

A Python library for reading, editing, and saving Excel (.xlsx) workbooks. It wraps openpyxl with a higher-level API for row-by-row reading, cell access, lock detection, and workbook persistence.

Requirements

  • Python 3.14+
  • Poetry (recommended) or pip

Installation

With Poetry

git clone <repository-url>
cd python-spreadsheet-reader
poetry install

With pip

pip install .

Quick start

from python_spreadsheet_reader.readers.xlsx import XLSXReader

reader = XLSXReader("path/to/workbook.xlsx")

# Read all rows from the active sheet (values only, keyed by cell coordinates)
sheet_data = reader.read_sheet(cell_values_only=True)

# Read a specific sheet
sheet_data = reader.read_sheet("Sheet2", cell_values_only=True)

# Access and modify cells
reader.load_workbook()
reader.set_cell_value(value="Hello", coords="A1")
reader.set_cell_value(value=42, row=2, col=1)

# Save changes
reader.save_spreadsheet()                          # overwrite original
reader.save_spreadsheet("output/copy.xlsx")      # save to a new path

reader.close_workbook()

Note: Close the workbook in Excel or LibreOffice before opening it with this library. If the file is in use, SpreadsheetIsLockedException is raised unless you pass read_locked=True to load_workbook() or read_sheet().

API overview

XLSXReader

Entry point for working with a .xlsx file. Holds the workbook in memory and optionally caches the result of read_sheet().

Member Description
workbook_path Path to the workbook passed to the constructor.
_sheet_data Cached row data from the last read_sheet() call when close_workbook=False.
_workbook Loaded openpyxl.Workbook, or None if closed.

Constructor

XLSXReader(workbook_path: str | Path)

Public methods

Method Returns Description
load_workbook(...) openpyxl.Workbook Opens the workbook with configurable read-only, formula, VBA, link, and rich-text options.
close_workbook() None Closes the workbook and clears the sheet data cache.
read_sheet(...) dict[int, dict] Reads rows from the active or named sheet. Each key is a 1-based row number; each value is a dict of cells keyed by coordinate (e.g. "A1") or column number.
get_cell(coords=..., row=..., col=..., sheet_name=...) Cell | MergedCell Returns a cell by Excel coordinate or 1-based row/column.
set_cell_value(value, coords=..., row=..., col=..., sheet_name=...) Cell | MergedCell Sets a cell value and returns the updated cell.
save_spreadsheet(workbook_path=None, close_workbook=True) Path Saves the workbook. Creates parent directories if needed.
is_spreadsheet_locked() bool Checks for Excel (~$filename) or LibreOffice (.~lock.filename#) lock files.
adicionar_imagem(...) — Not implemented — raises NotImplementedError.

read_sheet() options

Parameter Default Description
sheet_name None Sheet to read; uses the active sheet when omitted.
cell_values_only False Return cell values instead of Cell objects.
return_cell_coords True Use coordinates ("A1") as keys; otherwise use column numbers.
read_only False Open in read-optimized mode (no edits).
keep_formulae True Return formulas instead of cached values.
read_locked False Allow reading while another app has the file open.
close_workbook True Close the workbook after reading.

Example read_sheet() output

{
    1: {"A1": "ID", "B1": "Title", "C1": "Genre"},
    2: {"A2": 123, "B2": "Alien", "C2": "Science Fiction, Horror"},
    3: {"A3": 124, "B3": "Predator", "C3": "Science Fiction, Action"},
}

Exceptions

All custom exceptions inherit from SpreadsheetReaderException.

Exception When raised
NoActiveSpreadsheetException The workbook has no active sheet when one is required.
SpreadsheetIsLockedException The file is open in Excel or LibreOffice and read_locked=False.

Other errors you may encounter:

  • FileNotFoundError — workbook path does not exist.
  • ValueError — unsupported file extension or missing cell coordinates.

Project structure

python-spreadsheet-reader/
├── python_spreadsheet_reader/
│   └── readers/
│       ├── xlsx.py          # XLSXReader
│       └── exceptions.py    # Custom exceptions
├── pyproject.toml
├── poetry.lock
└── README.md

Dependencies

  • openpyxl — read and write .xlsx files
  • Pillow — image support for openpyxl
  • ipykernel — Jupyter kernel support

License

See the repository maintainers for licensing information.

Metadata

Release files for python-spreadsheet-reader 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-spreadsheet-reader 2.1.0
File Size Uploaded Provenance Actions
python_spreadsheet_reader-2.1.0.tar.gz 9.8 kB Without provenance Details for python_spreadsheet_reader-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-spreadsheet-reader 2.1.0
File Interpreter ABI Platform Actions
python_spreadsheet_reader-2.1.0-py3-none-any.whl Python 3 none any Details for python_spreadsheet_reader-2.1.0-py3-none-any.whl

Total release size: 21.6 kB

Release files / python_spreadsheet_reader-2.1.0.tar.gz

Download URL python_spreadsheet_reader-2.1.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
977a3859ba4a1885f55a34680ceb420633fc1b3ad06b9fe5c0bad50c27790c02
BLAKE2b-256 checksum
How to use checksums
57c9b4102325d8f3b4d33bff24ea895c382fe8288ff65f1b9b4080d4dee3c481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.14.5 Windows/10

Release files / python_spreadsheet_reader-2.1.0-py3-none-any.whl

Download URL python_spreadsheet_reader-2.1.0-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ca0afc598dbf1a9de8c6a352be92a8e177e24d96d1fd6ce3d93cfe83d9b70c3
BLAKE2b-256 checksum
How to use checksums
db5d3d24f22241f70c04648dcc64b73777a334d152b6f869be0bd2d067a1aa15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.14.5 Windows/10

Security for python-spreadsheet-reader 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page