Jul-05-2017, 10:02 AM
Python -- 3.5 pip 8.1.2 openpyxl centos 7
I am trying to read an excel file using above specifications. So i loop through all rows in an excel file and find a cell value matching regular expression and if that cell value is found then I should check the next immediate row is empty and if its empty I should print the name of the sheet.
I am trying to read an excel file using above specifications. So i loop through all rows in an excel file and find a cell value matching regular expression and if that cell value is found then I should check the next immediate row is empty and if its empty I should print the name of the sheet.
#!/usr/bin/python3.5
import os, sys, re
from re import *
from openpyxl import *
f = "/root/python/countsheets/sample.xlsx"
print (f)
wb = load_workbook(f)
for sheet in wb:
print ("\n")
print ("Checking Sheet:", sheet)
# looping through all rows and first column
for row in sheet.iter_rows('A{}:A{}'.format(sheet.min_row,sheet.max_row)):
for col in sheet.iter_cols(min_col=1,max_col=1):
for cell in row:
# printing all cell values from all rows and first column
cv = cell.value
# matching regular expression with cell value
m = re.search(r"^yang*type*", str(cv))
print (cell.row,cell.column)
if m == cv:
print (cell.coordinate)
else:
print ("Not found")How can I get into next row after finding cell value and check if it is empty?
