Openpyxl Read Data From Cell




  • We can read the data that we have previously written in the cell.
  • There are two methods to read a cell, firstly we can access it by cell name, and secondly, we can access it by the cell() function.

For example, we are reading the data from the Wikitechy.xlsx file.

Sample Code

Import openpyxl
wb = openpyxl.load_workbook('Wikitechy.xlsx')  
sheet = wb.active
x1 = sheet['A1']  
x2 = sheet['A2']  
#using cell() function  
x3 = sheet.cell(row=3, column=1)  
print("The first cell value:",x1.value)  
print("The second cell value:",x2.value)  
print("The third cell value:",x3.value)  

Output

The first cell value: 618
The second cell value: Wikitechy
The third cell value: 30.15

Open Read Multiple Cells

We can read the values from the multiple cells. within the following example, we've marks.xlsx named excel file and that we will read each cell of file using the range operator.

 Openpyxl Multiple Data

Openpyxl Multiple Data

Sample Code

import openpyxl
wb = openpyxl.load_workbook('marks.xlsx')  
sheet = wb.active
cells = sheet['A1','B7']  
# cells behave like range operator  
for i1,i2 in cells:  
print("{0:8} {1:8}".format(i1.value,i2.value))  

Output

subjectmark
html89
css67
php 96
cloud 79
CN67
python85


Related Searches to Openpyxl Read Data From Cell

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×