Install XLRD in Python

Install XLRD in Python

This article introduces how to install xlrd in Python.

Install xlrd in Python

Sometimes while working in Python, we need to work with spreadsheets. Python has many solutions for working in spreadsheets, and the xlrd module is one of them.

Using the xlrd module, we can retrieve information, read, write and modify spreadsheet data. We can also go through various sheets and retrieve data from multiple spreadsheets.

As shown below, we can easily install the xlrd module using pip.

# python
pip install xlrd

If you have pip with a version lower than 3, this command will not work. Use the command below instead.

# python
pip3 install xlrd

We will go through an example in which we will access a spreadsheet and get its content using xlrd.

So let’s create a new spreadsheet with columns such as the name, email, and roll number and add some data as shown below.

excel file for xlrd

Now, let’s try to get data from the spreadsheet.

# python
import xlrd

# Location of the ile
location = ("spreadsheet.xls")

# To open Sheet
workB = xlrd.open_workbook(location)
worksheet = workB.sheet_by_index(0)

# For row 0 and column 0
print(worksheet.cell_value(0, 0))

When we run the above code, the output will be:

get data from excel using xlrd

So, in this way, we can easily install the xlrd module and use it to work with spreadsheets. The xlrd module has many functions to perform different tasks related to spreadsheets with the help of these functions.

Rana Hasnain Khan avatar Rana Hasnain Khan avatar

Rana is a computer science graduate passionate about helping people to build and diagnose scalable web application problems and problems developers face across the full-stack.

LinkedIn