Hi all,
I want to remove the duplicate rows of one excel by comparing with another excel.
Scenario is there are two excels, In 1st excel in ‘A’ column there are list of values which need to compare with another list of values present in another excel.If there are same values then i need to remove that row in the excel.
Can anyone please provide me a solution to solve this issue.
hey @Shivaraju,
you first need to get two DataTables by reading both the excel sheets. Also, you need two nested(one inside other) foreach loops (first one for iterating through rows of first DataTable and second one to iterate through rows of second DataTable). Now, inside the body of inner foreach take an “if” acitivity.
The condition you need to give here is "if data in all the cells of the ith row of first DataTable is equal to the data in all the cells of jth row of second DataTable using “AND” because rows should match exactly.
Further, in the body of “if” activity use “remove data row” activity to remove that common row from second DataTable. And then write this DataTable to the second excel file.
It is working fine to me … I cannot see the problem …did you get any error? the only thing is that you shoud add maybe the header to the column in the final excel
Compare Two data tables & get matches.
Here the Dt_OutPut contains the rows which is matched.
Dt_OutPut=(From row In dt1.AsEnumerable() where (From a In dt1.AsEnumerable() Join b In dt2.AsEnumerable() On a(“ColName_Dt1”).ToString() Equals b(“colName_Dt2”).ToString() select a).Contains(row) select row).CopyToDataTable()
Note: In the above query , Dt1 and Dt2 is compared and it took the matched rows from Dt1. Incase if u want to Get the matched rows from Dt2 then instead of select a you have to give select b.