Convert Excel to TSV with Python
Write worksheet rows with tab separators and ordinary CSV quoting for tabs and newlines.
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 openpyxlimport csv
from openpyxl import load_workbook
workbook = load_workbook("input.xlsx", read_only=True, data_only=True)
sheet = workbook["Inventory"]
with open("output.tsv", "w", encoding="utf-8", newline="") as output:
writer = csv.writer(output, delimiter="\t")
writer.writerows(sheet.iter_rows(values_only=True))
workbook.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.
- Empty cells become empty fields. Import untrusted formula-looking values as text in spreadsheet applications.
Documentation: openpyxl tutorial and workbook loading options