Introduction
Python has many repositories that give the reading feature in python to read Excel files easily. So, I will use openpyxl repositories for reading data from excel file.openpyxl have many methods for reading data from excel file.
- Install the repositories using command prompt type command: pip install openpyxl,

- I have Excel as below,

- Now we will do some operation on this excel file that is saved on desktop.
- Now we open Excel file using python code.
- Write python in the command line.
- It will open python terminal then write some code for reading xlsx file.
Output: <class 'openpyxl.workbook.workbook.Workbook'>
- import openpyxl
- data = openpyxl.load_workbook('desktop/demo.xlsx')
- type(data)

- Now we have to see all the workbook in excel
Output : ['Sheet1']
- data.get_sheet_names()

- data.get_sheet_names()
- Now we create a sheet objects for fetching cell values through this sheet object.
Output : ‘first_name’
- sheet = data.get_sheet_by_name('Sheet1')
- sheet['A1'].value

- Getting First column value from excel sheet:
Output:
- for cell in range(1,17):
- print(cell,sheet.cell(row=cell,column=1).value)
1 first_nam2 James3 Josephine4 Art5 Lenna6 Donette7 Simona8 Mitsue9 Leota10 Sage11 Kris12 Minna13 Abel14 Kiley15 Graciela16 Cammy
- Get maximum row and column in sheet.
Output: 17
- sheet.max_row
Output: 7- sheet.max_column

- sheet.max_row
- Getting All results from using python code,
- for r in range(1,17):
- print(r,sheet.cell(row=r,column=1).value,sheet.cell(row=r,column=2).value,sheet.cell(row=r,column=3).value,sheet.cell(row=r,column=4).value,sheet.cell(row=r,colun=5).value,sheet.cell(row=r,column=6).value,sheet.cell(row=r,column=7).value)
Output :1 first_name last_name company_name address city county state2 James Butt Benton, John B Jr 6649 N Blue Gum St New Orleans Orleans LA3 Josephine Darakjy Chanay, Jeffrey A Esq 4 B Blue Ridge Blvd Brighton L4 Art Venere Chemel, James L Cpa 8 W Cerritos Ave #54 Bridgeport Glouces5 Lenna Paprocki Feltz Printing Service 639 Main St Anchorage Anchorage6 Donette Foller Printing Dimensions 34 Center St Hamilton Butler OH7 Simona Morasca Chapman, Ross E Esq 3 Mcauley Dr Ashland Ashland OH8 Mitsue Tollner Morlong Associates 7 Eads St Chicago Cook IL9 Leota Dilliard Commercial Press 7 W Jackson Blvd San Jose Santa Clara10 Sage Wieser Truhlar And Truhlar Attys 5 Boston Ave #88 Sioux Falls Mi11 Kris Marrier King, Christopher A Esq 228 Runamuck Pl #2808 Baltimore12 Minna Amigon Dorl, James J Esq 2371 Jerrold Ave Kulpsville Montgomery13 Abel Maclead Rangoni Of Florence 37275 St Rt 17m M Middle Island Suf14 Kiley Caldarera Feiner Bros 25 E 75th St #69 Los Angeles Los Angeles15 Graciela Ruta Buckley Miller & Wright 98 Connecticut Ave Nw Chagrin F16 Cammy Albares Rousseaux, Michael Esq 56 E Morehead St Laredo Webb TX
So openpyxl gives many methods to real excel files that give many features to use excel files in many ways.

Gagan SikriPosted May 11, 2016, 1:27 PM
Nice One :)