Skip to content

Instantly share code, notes, and snippets.

Last active March 10, 2022 10:45
What would you like to do?
How to open Excel files in Python without pandas

How to open Excel files in Python without pandas

The pandas data-analysis tool can do almost everything. And because it can do almost everything, it's a massive hunk of code. So you might not want to include it in your project if you can avoid taking on the weight.

One of pandas' handiest features is quickly opening Excel spreadsheets. If that's all you need, here's how to accomplish the task with openpyxl, a much lighter dependency.

import pandas as pd
# In pandas, it's one easy line. Pretty nice.
df = pd.read_excel("./example.xlsx")
from openpyxl import load_workbook
# Open up the Excel file.
workbook = load_workbook(filename="./example.xlsx")
# Get the first sheet.
worksheet = workbook.worksheets[0]
# Convert the sheet to a list of lists.
row_list = []
for r in worksheet.rows:
column = [cell.value for cell in r]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment