Compare 2 excel files using Python -


i have 2 xlsx files follows:

value1   value2   value3 0.456   3.456    0.4325436 6.24654 0.235435 6.376546 4.26545 4.264543 7.2564523 

and

value1   value2  value3 0.456   3.456    0.4325436 6.24654 0.23546  6.376546 4.26545 4.264543 7.2564523 

i need compare cells, , if cell file1 != cell file2 print that.

import xlrd rb = xlrd.open_workbook('file1.xlsx') rb1 = xlrd.open_workbook('file2.xlsx') sheet = rb.sheet_by_index(0) rownum in range(sheet.nrows):     row = sheet.row_values(rownum)     c_el in row:         print c_el 

how can add comparison cell of file1 , file2 ?

the following approach should started:

from itertools import izip_longest import xlrd  rb1 = xlrd.open_workbook('file1.xlsx') rb2 = xlrd.open_workbook('file2.xlsx')  sheet1 = rb1.sheet_by_index(0) sheet2 = rb2.sheet_by_index(0)  rownum in range(max(sheet1.nrows, sheet2.nrows)):     if rownum < sheet1.nrows:         row_rb1 = sheet1.row_values(rownum)         row_rb2 = sheet2.row_values(rownum)          colnum, (c1, c2) in enumerate(izip_longest(row_rb1, row_rb2)):             if c1 != c2:                 print "row {} col {} - {} != {}".format(rownum+1, colnum+1, c1, c2)     else:         print "row {} missing".format(rownum+1) 

this display cells different between 2 files. given 2 files, display:

row 3 col 2 - 0.235435 != 0.23546 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -