I have tried to compare 2 excel files. It is working when it is in range but when not in range it is displaying an error.
Note: In range I mean, the 1st excel file has 5 rows and 5 columns, the 2nd excel file have more or less rows than the 1st excel file and same number of column.
How can I achieve this?
The code are as below:
from itertools import izip_longest
import xlrd
rb1 = xlrd.open_workbook('a.xlsx')
rb2 = xlrd.open_workbook('b.xlsx')
sheet1 = rb1.sheet_by_index(0)
sheet2 = rb2.sheet_by_index(0)
for rownum in range(max(sheet1.nrows, sheet2.nrows)):
if rownum < sheet1.nrows:
row_rb1 = sheet1.row_values(rownum)
row_rb2 = sheet2.row_values(rownum)
for colnum, (c1, c2) in enumerate(izip_longest(row_rb1, row_rb2)):
if c1 != c2:***emphasized text***
print "Row {} Col {} - {} != {}".format(rownum+1, colnum+1, c1, c2)
else:
print "Row {} missing".format(rownum+1)