View Excel sheets with Python
List worksheet names and inspect the first ten rows without printing the entire 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 load_workbook
with_workbook = load_workbook("input.xlsx", read_only=True, data_only=True)
print(with_workbook.sheetnames)
sheet = with_workbook["Inventory"]
print("Rows:", sheet.max_row, "Columns:", sheet.max_column)
for row in sheet.iter_rows(max_row=10, values_only=True):
print(row)
with_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.
- Worksheet dimensions are saved metadata; files with incorrect dimensions may need inspection before trusting those counts.
Documentation: openpyxl tutorial and workbook loading options