Sunday, May 17, 2009

Comparing Excel Files

While testing any reporting application, one comes under situations when he/she have to compare two excel files. If the excel sheets are small, its easier to compare them manually but as long the sheets becomes large, you need some automated way to compare those.
Earlier, i used to export those files as csv and then comparing them using perl scripts but it was an overhead to exporting and then comparing so i thought of doing something within the excel sheets itself. After googling, i found that it can be done by using Excel Macros. I did try that, but found that you need to open those excel files in Microsoft Excel and then apply the macro, which again i didn't like as it require to open MS Excel. I was interested to have a program which i can run from command prompt. Finally i got my solution. I converted the above macro as a standalone vb script program and used it from command prompt.
The great benefit with this script is that i can take control of displaying the diff results (currently, i am highlighting the rows in the excel sheet itself.)

to run this program, open command prompt and run following command:

C:\> cscript /nologo ExcelCompare.vbs <ExcelFile1> <ExcelFile2>

Following is the program:

No comments: