I have two excel files, Master and Work. I want to check whether the column “MasterNumber” in MasterFile.xlsx matches with the “WorkNumber” column in WorkFile.xlsx. If the columns match, write the specific row of data from the Master file into the Work File. In case the column doesn’t match/duplicate values, print ‘0’ in front of those columns.
Please help me with a solved XAML file for the above scenario.
I tried this using Write Cell activity and it worked perfectly. But due to 1000 rows, can’t proceed with writing cell currently, thus need another solution.
My Solution: MergeDT.xaml (23.6 KB)
Sorry for the confusion, could you input this linq query over there and let me know if any error arrises
The right side is, (From rowWork In dtWork.AsEnumerable Group Join rowMaster In dtMaster.AsEnumerable On rowWork("WorkNumber") Equals rowMaster("MasterNumber") Into master = Group From row In master.DefaultIfEmpty() Select ra ={rowWork(0),rowWork(1),rowWork(2),rowWork(3),If(row Is Nothing, 0, row(0)),If(row Is Nothing, 0, row(1)),If(row Is Nothing, 0, row(2))} Select dtOutput.Rows.Add(ra)).copyToDataTable
We read work excel sheet and assign it in a variable dtWork. Similar is done for Master excel sheet and stored in dtMaster.
Then we take each row from the datatables where rowWork is from dtWork and rowMaster is from dtMaster, both the tables are joined based on the condition that workNumber is equal to masterNumber.
The type of join is left outer join where we get all data of dtwork and matched columns of dtMaster. In the above code outer join is reffered to as Group Join and we group the joined contents into a group known as Master
From each row in the group master we select the columns of dtMaster and checking if its nothing, If the content is null or nothing it is replaced by 0, else it takes the matched content from dtMaster. To this we add dtWork columns
Finally the data selected is added row wise into the output datatable - dtOutput
What you’re trying to do is called a join, it’s a standard database operation. Use the Join Data Table activity. After that, whichever rows have blank values, you can update to 0 with a For Each Row in Datatable or LINQ.