I have an Excel file with some data, and I don’t want to add any duplicate rows while adding data repeatedly.
Are you using Workbook activity followed by LINQ or Are you using Excel Activities?
Yes, I’m using excel activities
you can use remove duplicate rows activity to remove duplicate rows from data table orelse you can use LINQ query to remove duplicate rows
Assuming you have 2 data tables (dt_Data, dt_NewValues). The dt_Data is from the excel, and dt_NewValues you are trying to add to the excel. You could use the Idea of Union of data tables using a simple LINQ, a faster approach.
Here is an example:
Data Table in Excel:
New Data Table to add:
Assign Statement:
dt_Data = dt_Data.AsEnumerable().Union(dt_NewValues.AsEnumerable(), DataRowComparer.Default).CopyToDataTable()
The OUTPUT:
If this solves your issue, Do mark it as a solution.
Happy Automation
Please follow below steps to achieve the same
- Read the Excel file into a data table - Named as dtExcel
- Assuming the name of the source data table which is expected to add to excel as dtSource
- Remove duplicates from dtSource using Remove Duplicate Activity if it is expected to have duplicates
- Start looping through dtSOurce using For Each Row in Data table activity
- The next step is to check whether the CurrentRow item is already available in Excel or not. For that use the below expression. For better performance - let’s use the Linq query in an if condition.
dtExcel.AsEnumerable().Any(Function(r) r(“Column1”).ToString().tolower().Contains(CurrentRow(“Column2”).ToString().ToLower()))
- If value contains - Ignore that row. Else add to excel
For reference / testing - you can use below XAML
Main.xaml (14.4 KB)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.