This method is using the Datatable Row Selection with the Help of Linq.
I have used two Query’s, One is to Select the records matching the Contract Number and Write the Result to the Delete Sheet and Another Query to Select the records Not matching the Contract Number and Write it to the Output Sheet.
However If you would need the Excel Color Format’s to be preserved as it is, you would need to create an output Template of the same format, and Write the Outputs to that Excel File.
Revert back if it is not the expected output that you needed.
@Siyu_Angela_Kuang Actually, Since I had that Input file, I used that excel file itself. You can write to a new Excel File, if that is what you needed.
Ok, Thanks! One more little Q: keep the previous conditions, what if I want to add one more condition, for instance, “Code” is empty. Output the duplicate rows that does not have code.
I guess I only need to change the assign “drArray = DT1.AsEnumerable().Where(function(row) DT2.AsEnumerable().Select(function(r) r(“Contract Number”).ToString).Any(function(x) x = row(“Contract Number”).ToString)).ToArray” part, but I don’t know how Can you please help?
@Siyu_Angela_Kuang Mostly, You would need to change the First Linq Query to the Below one :
DT1.AsEnumerable().Where(function(row) DT2.AsEnumerable().Select(function(r) r).Any(function(x) x("Contract Number").ToString.Equals(row("Contract Number").ToString) and String.IsNullOrWhiteSpace(x("Code").ToString))).ToArray
The Second Linq Query to the Below one :
DT1.AsEnumerable().Where(function(row) Not DT2.AsEnumerable().Select(function(r) r).Any(function(x) x("Contract Number").ToString.Equals(row("Contract Number").ToString) and String.IsNullOrWhiteSpace(x("Code").ToString))).ToArray
Can you check and revert back if it doesn’t work ?
Hi Superman,
I have one more Question related to the sheets:
I want to classify data in “DT1” according to different grades provided in DT2:
e.g. if (grade = 1 or 2 and OD = 5-7), add the rows to the “Delete” sheet;
if (grade > 2 and OD = 5-7), add the rows to the “OD5” sheet;
if (grade = 1 or 2 and OD = 11-13), add the rows to the “OD11” sheet.
Please see the screen shot for more explanation:
add a column (“grade”) in sheet 1 before “Contract Number” , and then
filter the data based on requirements provided? still only need to change the “Assign drArray” part?
I tried to write it in UiPath by modifying the you gave me earlier, but failed
@Siyu_Angela_Kuang Can you send the excel files , It is mostly similar to the Linq I have given earlier, You might just need to add more Conditions, and additional separate queries for the outputs you require.
@Siyu_Angela_Kuang When I apply the Conditions to get the respective outputs, I get the OD5 Sheet Output and Delete Sheet output correctly. But I only get one row in OD11 Sheet instead of 3 rows. Can you cross and verify if that’s the actual result or Is there more condition to be applied.