Hi Guys,
i need to compare between column name in 2 excel and copy all row in that column name.
how do i do it?
Hi Guys,
i need to compare between column name in 2 excel and copy all row in that column name.
how do i do it?
Sure
Sample Input
Expected Output
Both are different excel file and they have different format of data table
This is the second excel.
Can you try below query
FinalDT = DT1.DefaultView.ToTable(False, DT1.Columns.Cast(Of DataColumn)() _
.Where(Function(col) DT2.Columns.Contains(col.ColumnName)) _
.Select(Function(col) col.ColumnName).ToArray())
Regards,
Another approach
Invoke Code:
resultDT = DT2.Clone()
For Each row As DataRow In DT1.Rows
Dim newRow As DataRow = resultDT.NewRow()
For Each col As DataColumn In resultDT.Columns
If DT1.Columns.Contains(col.ColumnName) Then
newRow(col.ColumnName) = row(col.ColumnName)
End If
Next
resultDT.Rows.Add(newRow)
Next
Input:
DT1
DT2
Output:
Regards,
i have run the invoke code. The data remove the header. All of the data is written starting at first row.
Hello @zaffan.isa ,
For what I understood you just want to insert all the rows from excel 1 on excel 2, based on the column name.
You can find a Xaml attached with a solution. You can improve the solution with LINQ if you prefer.
If you have any doubt feel free to reach me.
Example.xaml (9.0 KB)
i forgot to declare the DT, my apologies.
But now, i am having another problem is that the written data is overwrite my header.
I am sorry i cannot share the xaml. Because it contain confidential information
i will try. thanks for suggest
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.