简体   繁体   中英

How to read a particular cell by using “wb = load_workbook('path', True)” in openpyxl

there

I have written code for reading the large excel files

but my requirement is to read a particular cell like for eg(cell(row,column) in a excel file when i kept True

in wb = load_workbook('Path', True)

any body please help me...

CODE:

 from openpyxl import load_workbook 

 wb = load_workbook('Path', True) 
 sheet_ranges = wb.get_sheet_by_name(name = 'Global') 
 for row in sheet_ranges.iter_rows(): 

     for cell in row: 
         print cell.internal_value 

Since you are using an Optimized Reader , you cannot just access an arbitrary cell using ws.cell(row, column).value :

cell, range, rows, columns methods and properties are disabled

Optimized reader was designed and created specially for reading an umlimited amount of data from an excel file by using iterators .

Basically you should iterate over rows and cells until you get the necessary cell. Here's a simple example:

for r, row in enumerate(sheet_ranges.iter_rows()):
    if r == 10: 
        for c, cell in enumerate(row): 
            if c == 5:
                print cell.internal_value

You can find the answer here . I recommend you consult the documentation first before asking a question on SO.

In particular, this is pretty much exactly what you want:

d = ws.cell(row = 4, column = 2)

where ws is a worksheet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM