Split Excel sheets with Python
Write each worksheet into its own values-only workbook.
View code and setup
Before you start
- Install Python 3. Create the environment below, save the Python example as task.py, then run .venv/bin/python task.py in the folder containing input.xlsx. On Windows, use py -m venv .venv and .venv\Scripts\python.exe in place of .venv/bin/python. Replace Inventory with your worksheet name.
python3 -m venv .venv
.venv/bin/python -m pip install openpyxlfrom openpyxl import Workbook, load_workbook
source = load_workbook("input.xlsx", read_only=True, data_only=True)
for number, sheet in enumerate(source.worksheets, start=1):
output = Workbook()
target = output.active
target.title = sheet.title
for row in sheet.iter_rows(values_only=True):
target.append(row)
output.save(f"sheet-{number}.xlsx")
source.close().venv/bin/python task.pyLimits and output
- These data recipes use saved cell results, not recalculated formulas. They do not copy charts, styles, macros or workbook relationships. Keep the original file.
- Outputs use numbered names rather than worksheet text as file paths. Each output contains one complete sheet; this example does not split by row count. Review formula-looking source text before writing it to a spreadsheet.
Documentation: openpyxl tutorial and workbook loading options