Python Read Excel File using xlrd

Python Python Excel Python File xlrd

In this tutorial we will learn how to read Excel file in Python using xlrd package.

Install xlrd package

Firstly you need to install xlrd package by command below.

pip install xlrd

Read Excel Spreadsheet in Python

To write code example we assump that you have the sample.xlsx Excel file with content as below in your machine.

Python Read Excel File using xlrd

Below is Python code example to read sample.xlsx Excel file content and sprint the content to terminal.

import xlrd

workbook = xlrd.open_workbook('D:\ToriCode\Python\sample.xlsx')
sheet = workbook.sheet_by_index(0)

for row in range(sheet.nrows):
    values = []
    for col in range(sheet.ncols):
        cell_value = sheet.cell_value(row, col)
        values.append(cell_value)
    print(','.join(values))

Run Python code above in your terminal to get the result as below.

Python Read Excel File using xlrd