{"id":323,"library":"openpyxl","title":"openpyxl","description":"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.","status":"active","version":"3.1.5","language":"python","source_language":"en","source_url":"https://github.com/openpyxl/openpyxl","tags":["Excel","xlsx","xlsm","Python","openpyxl"],"install":[{"cmd":"pip install openpyxl","lang":"bash","label":"Install openpyxl"}],"dependencies":[{"reason":"To 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))","package":"defusedxml","optional":true}],"imports":[{"note":"Ensure correct import path to avoid ImportError.","symbol":"Workbook","correct":"from openpyxl import Workbook"}],"quickstart":{"code":"from openpyxl import Workbook\n\n# Create a new workbook and select the active worksheet\nwb = Workbook()\nws = wb.active\n\n# Write data to a cell\nws['A1'] = 'Hello, World!'\n\n# Save the workbook\nwb.save('example.xlsx')","lang":"python","description":"A simple example to create a new Excel file and write data to it."},"warnings":[{"fix":"Install 'defusedxml' using pip: pip install defusedxml","message":"Openpyxl 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))","severity":"breaking","affected_versions":"all"},{"fix":"Use a virtual environment for pip operations or explicitly manage --root-user-action. To update pip, run: pip install --upgrade pip","message":"Running 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'2010':8 '3.1.5':13 'activ':16 'current':11 'excel':7,25,30 'featur':26 'file':10 'latest':24 'librari':4 'maintain':17 'openpyxl':1,14,34 'python':3,28,33 'read/write':6 'regular':19 'support':22 'updat':20 'version':12,29 'xlsm':32 'xlsx':31 'xlsx/xlsm':9","created_at":"2026-03-28T08:31:20.189924+00:00","updated_at":"2026-04-16T17:37:09.922064+00:00","problems":[{"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.","cause":"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.","error":"ModuleNotFoundError: No module named 'openpyxl'"},{"fix":"Access worksheets directly using dictionary-like syntax: `worksheet = workbook['SheetName']` or iterate through `workbook.sheetnames`.","cause":"The `get_sheet_by_name()` method was deprecated in openpyxl 2.4 and removed in later versions.","error":"AttributeError: 'Workbook' object has no attribute 'get_sheet_by_name'"},{"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.","cause":"The specified Excel file does not exist at the given path, or the path is incorrect relative to the script's working directory.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'your_file.xlsx'"},{"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.","cause":"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.","error":"AttributeError: 'NoneType' object has no attribute 'value'"},{"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.","cause":"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.","error":"ValueError: Invalid file path or buffer object type: <class 'openpyxl.workbook.workbook.Workbook'>"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.1.5","cli_name":"","cli_version":null,"type":"library","homepage":"https://openpyxl.readthedocs.io","github":null,"docs":"https://openpyxl.readthedocs.io/en/stable/","changelog":null,"pypi":"https://pypi.org/project/openpyxl/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}