January 2019
Beginner
318 pages
8h 23m
English
In this section, we will look at how to read an Excel file. We are going to use the xlrd module. Create a script called read_excel.py and write the following content in it:
import xlrdexcel_file = (r"/home/student/sample.xlsx")book_obj = xlrd.open_workbook(excel_file)excel_sheet = book_obj.sheet_by_index(0)result = excel_sheet.cell_value(0, 1)print(result)
Run the script and you will get the following output:
student@ubuntu:~$ python3 read_excel.py
Following is the output:
First Name
In the preceding example, we imported the xlrd module to read the Excel file. We also mentioned the location of the Excel file. Then, we created a file object, then we mentioned the index value, so that the reading will start from that ...
Read now
Unlock full access