Registry / data / openpyxl

openpyxl

JSON →
library3.1.5pypypi✓ verified 52d ago

A Python library to read/write Excel 2010 xlsx/xlsm files. Current version: 3.1.5. Openpyxl is actively maintained with regular updates to support the latest Excel features and Python versions.

dataserialization
pip install openpyxl
Install & Compatibility
Where this runs
tested against v3.1.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.336s · 20.5MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.7s · import 0.305s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Workbook
from openpyxl import Workbook
Ensure correct import path to avoid ImportError.

A simple example to create a new Excel file and write data to it.

from openpyxl import Workbook # Create a new workbook and select the active worksheet wb = Workbook() ws = wb.active # Write data to a cell ws['A1'] = 'Hello, World!' # Save the workbook wb.save('example.xlsx')
Debug
Known issues
breakingOpenpyxl does not guard against XML-based attacks like quadratic blowup or billion laughs attacks by default. To mitigate these risks, install the 'defusedxml' package. ([openpyxl.readthedocs.io](https://openpyxl.readthedocs.io/en/3.1.0/?utm_source=openai))
fix
Install 'defusedxml' using pip: pip install defusedxml
affects: all
gotchaRunning pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead. Also, a new release of pip is available.
fix
Use a virtual environment for pip operations or explicitly manage --root-user-action. To update pip, run: pip install --upgrade pip
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'openpyxl'
The openpyxl library is not installed in the Python environment being used, or there is a mismatch between the Python version where openpyxl was installed and the Python interpreter running the code.
fix
Install openpyxl using pip: `pip install openpyxl` or `python -m pip install openpyxl`. If using virtual environments, ensure it's installed in the active environment.
AttributeError: 'Workbook' object has no attribute 'get_sheet_by_name'
The `get_sheet_by_name()` method was deprecated in openpyxl 2.4 and removed in later versions.
fix
Access worksheets directly using dictionary-like syntax: `worksheet = workbook['SheetName']` or iterate through `workbook.sheetnames`.
FileNotFoundError: [Errno 2] No such file or directory: 'your_file.xlsx'
The specified Excel file does not exist at the given path, or the path is incorrect relative to the script's working directory.
fix
Verify the file name and its full path. Ensure the file is in the same directory as the script, or provide an absolute path to the file.
AttributeError: 'NoneType' object has no attribute 'value'
This typically occurs when trying to access the 'value' attribute of a cell that is empty or a variable that was expected to hold a cell object but instead received `None`, often because a cell was out of range or a worksheet was not properly loaded.
fix
Before accessing `.value`, check if the cell object is not `None`. For example, `if cell is not None: print(cell.value)`. Ensure correct cell referencing and that the workbook/worksheet is loaded correctly.
ValueError: Invalid file path or buffer object type: <class 'openpyxl.workbook.workbook.Workbook'>
This error often occurs when attempting to pass an `openpyxl.workbook.Workbook` object to a function (e.g., `pandas.read_excel`) that expects a file path, file-like object, or buffer, not an already-loaded `openpyxl` workbook object.
fix
Pass the file path directly to the function expecting it, or if you must use a loaded openpyxl workbook, save it to a buffer first if the target function supports buffer input. For `pandas.read_excel`, either provide the file path directly or ensure the 'engine' parameter is set correctly if passing a file-like object.
Upgrade
Version history
3.1.5latest on PyPI
Audit
Dependencies
defusedxmloptionalTo guard against XML-based attacks like quadratic blowup or billion laughs attacks. Openpyxl does not guard against these attacks by default. ([openpyxl.readthedocs.io](https://openpyxl.readthedocs.io/en/3.1.0/?utm_source=openai))
Agent activity
14 hits · last 30 days
node
4
seranking-bot
4
ahrefsbot
2
Meta
1
Amazon
1
oai-searchbot
1
Resources