How to Open and Read Xlsx File in Python?

By Hardik Savani September 3, 2022 Category : Python

Hello Guys,

In this tutorial, we will go over the demonstration of how to open and read xlsx file in python. you can see how to open xlsx file in python. This article goes in detailed on how to open xlsx file in python using xlrd. you will learn python read xlsx file line by line.

There are several modules and ways to read xlsx files in python. i will give you simple two examples using pandas and openpyxl to read and get xlsx file data. so let's see both examples one by one.

You can use these examples with python3 (Python 3) version.

I simply created data.xlsx file with content as like below, we will use same file for both example:


Example 1: using pandas

# import pandas library as pd
import pandas as pd
# get by default 1st sheet of demo excel file
data = pd.read_excel('demo.xlsx')


   ID             Name              Email
0   1    Hardik Savani
1   2  Vimal Kashiyani
2   3   Harshad Pathak

Example 2: using openpyxl

import openpyxl
# Define variable to load the dataframe
dataframe = openpyxl.load_workbook("demo.xlsx")
# Define variable to read sheet
data =
# Display Row Data
for row in range(0, data.max_row):
    for col in data.iter_cols(1, data.max_column):


Hardik Savani
Vimal Kashiyani
Harshad Pathak

I hope it can help you...

Tags :