Read Excel from Python

First we need to import xlrd module

then open the workbook and read cell by cell 

Complete code given below-


import xlrd

#loc = (r'C:\Users\xyz\Python_Local\MyExcel.xls')

#print(loc)

wb = xlrd.open_workbook(r'C:\Users\xyz\Python_Local\File1.xls')

sheet = wb.sheet_by_index(0)

# For row 0 and column 0

sheet.cell_value(0, 0)

# Extracting number of columns

print(sheet.ncols)

# Extracting number of rows

print(sheet.nrows)

Comments

Popular posts from this blog

[Solved]SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Read the excel and insert data into My SQL using Python