Read Excel Python Example | How to Read Data from Excel File in Python

In this Python Tutorial Learn How to Read Excel Python data using openpyxl. openpyxl is a Python Library that one can use to Read and write Excel Data.

Read Excel Python Example

Read Excel Python Example | How to Read Data from Excel File in Python
Read Excel Python

In this tutorial, we have used a Microsoft Excel 2016 (.xlsx) file. The file contains sample data about a company’s sale on a particular Date, Name of its customer, Item sold, Units sold, Unit Cost and the Total amount charged! You can Copy Paste the data in an Excel Workbook from below:

OrderDate Name Item Units UnitCost Total
06-04-2018 Jones Pencil 95 1.99 189.05
06-04-2018 Kivell Binder 50 19.99 999.5
06-04-2018 Jardine Pencil 36 4.99 179.64
06-04-2018 Gill Pen 27 19.99 539.73
06-04-2018 Sorvino Pencil 56 2.99 167.44
06-04-2018 Jones Binder 60 4.99 299.4
06-04-2018 Andrews Pencil 75 1.99 149.25
06-04-2018 Jardine Pencil 90 4.99 449.1
06-04-2018 Thompson Pencil 32 1.99 63.68
06-04-2018 Jones Binder 60 8.99 539.4
06-04-2018 Morgan Pencil 90 4.99 449.1
06-04-2018 Howard Binder 29 1.99 57.71
06-04-2018 Parent Binder 81 19.99 1,619.19
06-04-2018 Jones Pencil 35 4.99 174.65
06-04-2018 Smith Desk 2 125 250
06-04-2018 Jones Pen Set 16 15.99 255.84
06-04-2018 Morgan Binder 28 8.99 251.72
06-04-2018 Jones Pen 64 8.99 575.36
06-04-2018 Parent Pen 15 19.99 299.85
06-04-2018 Kivell Pen Set 96 4.99 479.04
06-04-2018 Smith Pencil 67 1.29 86.43
06-04-2018 Parent Pen Set 74 15.99 1,183.26
06-04-2018 Gill Binder 46 8.99 413.54
06-04-2018 Smith Binder 87 15 1,305.00
06-04-2018 Jones Binder 4 4.99 19.96
06-04-2018 Sorvino Binder 7 19.99 139.93
06-04-2018 Jardine Pen Set 50 4.99 249.5
06-04-2018 Andrews Pencil 66 1.99 131.34
06-04-2018 Howard Pen 96 4.99 479.04
06-04-2018 Gill Pencil 53 1.29 68.37
06-04-2018 Gill Binder 80 8.99 719.2
06-04-2018 Kivell Desk 5 125 625
06-04-2018 Jones Pen Set 62 4.99 309.38
06-04-2018 Morgan Pen Set 55 12.49 686.95
06-04-2018 Kivell Pen Set 42 23.95 1,005.90
06-04-2018 Sorvino Desk 3 275 825
06-04-2018 Gill Pencil 7 1.29 9.03
06-04-2018 Sorvino Pen 76 1.99 151.24
06-04-2018 Thompson Binder 57 19.99 1,139.43
06-04-2018 Andrews Pencil 14 1.29 18.06
06-04-2018 Jardine Binder 11 4.99 54.89
06-04-2018 Jardine Binder 94 19.99 1,879.06
06-04-2018 Andrews Binder 28 4.99 139.72

Read Excel Python Tutorial: Steps to be taken to read a particular cell from Excel in Python:

1.Open PyCharm and go to File > Settings > Project > Project Interpreter. Click on ‘+’ sign and import Python openpyxl library.

2. Once imported, write following lines of code in a new Python file:

Read Excel Python
#import package in Python file
import openpyxl
data = openpyxl.load_workbook('sales.xlsx')

#Select active worksheet
salesData = data.active

#Set value to a variable and print it
a = salesData['C2']
print(a.value)

Read Excel Python Tutorial: Steps to be taken to read a Group of Cell from Excel in Python:

Read Excel Python
import openpyxl
data = openpyxl.load_workbook('sales.xlsx')
salesData = data.active

#Select the Range
custName = salesData['A1':'F44']

#Use For x in y
for date,name,item,units,cost,total in custName:

#Code to read excel python data: print ("{column : row}".format(x.value))
print("{0:44} {1:44} {2:44} {3:44} {4:44} {5:44}".format(date.value,name.value,item.value,units.value,cost.value,total.value))

Run both the codes and let us know about your Experience below. To know more about Python Programming read here.

To learn how to parse JSON data in Python, read here.