{"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,"last_verified":"2026-05-12T13:03:51.585Z","next_check":"2026-06-26T00:00:00.000Z","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,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.31,"mem_mb":7.5,"disk_size":"20.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":7.5,"disk_size":"21M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.41,"mem_mb":7.9,"disk_size":"22.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":7.9,"disk_size":"23M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.35,"mem_mb":7.7,"disk_size":"14.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":7.7,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":8.2,"disk_size":"14.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.38,"mem_mb":8.2,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.31,"mem_mb":7.6,"disk_size":"20.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.28,"mem_mb":7.6,"disk_size":"20M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}