Using xlrd module, one can retrieve information from a spreadsheet. For example, reading, writing or modifying the data can be done in Python. Also, the user might have to go through various sheets and retrieve data based on some criteria or modify some rows and columns and do a lot of work.
xlrd module is used to extract data from a spreadsheet.
Command to install xlrd module :
pip install xlrd
Input File:

Code #1: Extract a specific cell
Python3
# Reading an excel file using Pythonimport xlrd# Give the location of the fileloc = ("path of file")# To open Workbookwb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)# For row 0 and column 0print(sheet.cell_value(0, 0)) |
Output :
'NAME'
Code #2: Extract the number of rows
Python3
# Program to extract number# of rows using Pythonimport xlrd# Give the location of the fileloc = ("path of file")wb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)sheet.cell_value(0, 0)# Extracting number of rowsprint(sheet.nrows) |
Output :
4
Code #3: Extract the number of columns
Python3
# Program to extract number of# columns in Pythonimport xlrdloc = ("path of file")wb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)# For row 0 and column 0sheet.cell_value(0, 0)# Extracting number of columnsprint(sheet.ncols) |
Output :
3
Code #4 : Extracting all columns name
Python3
# Program extracting all columns# name in Pythonimport xlrdloc = ("path of file")wb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)# For row 0 and column 0sheet.cell_value(0, 0)for i in range(sheet.ncols): print(sheet.cell_value(0, i)) |
Output :
NAME SEMESTER ROLL NO
Code #5: Extract the first column
Python3
# Program extracting first columnimport xlrdloc = ("path of file")wb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)sheet.cell_value(0, 0)for i in range(sheet.nrows): print(sheet.cell_value(i, 0)) |
Output :
NAME ALEX CLAY JUSTIN
Code #6: Extract a particular row value
Python3
# Program to extract a particular row valueimport xlrdloc = ("path of file")wb = xlrd.open_workbook(loc)sheet = wb.sheet_by_index(0)sheet.cell_value(0, 0)print(sheet.row_values(1)) |
Output :
['ALEX', 4.0, 2011272.0]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Reading an excel file using Python openpyxl module
- Create a GUI to convert CSV file into excel file using Python
- Python | Writing to an excel file using openpyxl module
- Python | Arithmetic operations in excel file using openpyxl
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Trigonometric operations in excel file using openpyxl
- Python | Create and write on excel file using xlsxwriter module
- How to import an excel file into Python using Pandas?
- How to extract Time data from an Excel file column using Pandas?
- How to extract Email column from Excel file and find out the type of mail using Pandas?
- How to import excel file and find a specific column using Pandas?
- How to extract date from Excel file using Pandas?
- Find the sum and maximum value of the two column in excel file using Pandas
- Python | Excel File Comparison
- Python | Split given list and insert in excel file
- Reading Python File-Like Objects from C | Python
- How to skip rows while reading csv file using Pandas?
- Reading specific columns of a CSV file using Pandas
- Exporting a Pandas DataFrame to an Excel file
- Python - Reading last N lines of a file
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

