0

You need to compare two Excel files, rows that are different need to write to a separate file, also write to a separate file changes that have occurred, namely: Id of the second file that differs from the first and the name of the column in which the change occurred and specify the value of two files that have changed, ie clearly show the change. I realized part of it, but I don't know how to move on. Please, help))

import os
import numpy as np
from itertools import zip_longest
import xlrd
rb1 = xlrd.open_workbook('Book1.xlsx')
rb2 = xlrd.open_workbook('Book2.xlsx')
sheet1 = rb1.sheet_by_index(0)
sheet2 = rb2.sheet_by_index(0)
for rownum in range(max(sheet1.nrows, sheet2.nrows)):
    if rownum < sheet2.nrows:
        row_rb1 = sheet1.row_values(rownum)
        row_rb2 = sheet2.row_values(rownum)
        for colnum, (c1, c2) in enumerate(zip_longest(row_rb1, row_rb2)):
            if c2 != c1:                
                file = open("test.txt", "a")
                # c1.np.concatenate([rownum.name, rownum])                
                file.write ("#RAW#{}#Col#{}#-#{}#!=#{}#   \n".format(rownum+1, xlrd.formula.colname(colnum), c1, c2, index=False ))
                file.close()
                print ("RAW {} Col {} - {}!={}  \n".format(rownum+1, xlrd.formula.colname(colnum), c1, c2 ))
    else:
        print ("RAW {} missing".format(rownum+1,index=False))
  • Maybe worth a read: [pandas.DataFrame.compare](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.compare.html) or [Compare two DataFrames and output their differences side-by-side](https://stackoverflow.com/questions/17095101/compare-two-dataframes-and-output-their-differences-side-by-side) – MDR Jul 26 '21 at 17:10

0 Answers0