How to Read Excel Spreadsheet using Python XLRD

In this article you can learn how to read excel spreadsheet using python module xlrd . 

 

import xlrd 

def open_file(path) : 
    #Open and read an Excel file 
    book=xlrd.open_workbook(path)
    #print number of sheets 
    print book.nsheets

    #print sheet names
    print book.sheet_names()

    #get the first worksheet
    first_sheet = book.sheet_by_index(0)

    
    #print first row of first sheet
    print first_sheet.row_values(0)

    #print number of row in sheet 
    print first_sheet.nrows
    n=first_sheet.nrows
    
    # iterate through rows read a row by row
    for i in range(1,n):
        row=first_sheet.row_values(i)
        for j,r in enumerate(row):
            print r
            

open_file('test.xls')

email@djangotutsme.com May 19, 2016, 8:33 a.m.