Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to read data from excel file using Openpyxl in python?

Description

To see how to extract data from an excel file using python3.

Process
Openpyxl:

   The openpyxl module allows Python program to read and modify Excel files.

   Its the open source library designed with python.

   We can read, write, rename , merge data using this module.

Sample Code

#import openpyxl module

import openpyxl

#create workbook object

wb=openpyxl.load_

workbook(‘Employee.xlsx’)

#data extract from sheet1

sheet=(wb[‘Sheet1’])

#take a data from a cell

a=sheet[‘B2’]

print(a.value)

print(a.column)

print(a.row)

b=sheet.cell(row=5,column=3)

print(b.value)

print(b.column)

print(b.row)

print(“\n”)

#reading entire row

print(“Reading whole row with Openpyxl\n”)

for c in range(1,7):

d=sheet.cell(row=3,column=c)

print(d.value)

print(“\n”)

#reading entire column

print(“Reading whole column with Openpyxl\n”)

for r in range(1,12):

d=sheet.cell(row=r,column=2)

print(d.value)

Screenshots
read data from excel file using Openpyxl in python
import openpyxl