1

I work at a script to extract some very messy data from a huge excel file and I run into a bump. There is any way to get coordinates from an empty cell with openpyxl?

This will return an error saying EmptyCell has no row/column attribute

for row in sheet.iter_rows():
    for cell in row:
        if cell.column is ... :
           print(cell.value)

I cannot skip the empty cells, as there are empty cells in some columns that have to taken into account and extracted as such in the new file. Also, I cannot fill the empty cells because the original file is huge and its opened read only because of this.

There is any way to do this with openpyxl or I should try to use another library?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dorin.D
  • 17
  • 4

2 Answers2

3

EmptyCell's are special cells in the read-only context: they are fillers created where there are no cells in the original XML so that rows from a range are of equal length. As such they do not really exist and hence do not have coordinates. If you need their coordinates then you can simply use enumerate to count for you while looping.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55
1
for row in sheet.iter_rows():  
       for cell in row:  
        if cell.value is None :  
           print(str(cell.column)+str(cell.row))  
ashim
  • 67
  • 1
  • 2
  • 12