Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

Break python loop when it finds 2 consecutive empty cells

$
0
0

I want to count the rows & columns present in an Excel table using a loop, and the loop should stop running on encountering 2 (or more) consecutive empty cells.

row_count=0
col_count=0

for a in range(1,temp.max_row+1):
   if temp.cell(row=a,column=2).value!=None:
       row_count= row_count+1
   else:
       break
for b in range(2,temp.max_column+1):
   if temp.cell(row=8,column=b).value!=None:
       col_count=col_count+1
   else:
       break
print(row_count)
print(col_count)

However, I cant get a correct result with the method used.


Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>