Excel Column Headers matching

Hello guys… I have 2 excel sheets… temp and ST, both of the sheets have same columns, I need to check whether the column headers of both the sheets matches/ or are same. But before doing that I need to add an extra column named controls to temp sheet only… and then I need to match column headers of ST to Temp ignoring the newly added column named controls. How can I do this in UIpath?

Hi

I believe There is no direct method to do this in studioX
If it’s fine with some coding expression as it is done in studioX then
Hope the below expressions and steps would help resolve this issue

Both the excel has to be read and save the output as a datatable temp and ST

  1. Use a save for later activity like this to get the column named in temp dt

arr_tempcolnames = (From dc In temp.Columns.Cast(Of DataColumn)
Select dc.ColumnName).ToArray()

  1. Use another save for later activity to get column names of ST datatable

arr_STColnames = (From dc In ST.Columns.Cast(Of DataColumn)
Select dc.ColumnName).ToArray()

Both arr_tempcolnames and atr_STcolunames are array of string variables

  1. Now use a INSERT column activity and mention the datatable as temp and mention the new ColumnName you want
    This will add the new column to that datatable at last

  2. Then to compare two array of column names use this expression in a IF activity

arr_tempcolnames.Except(arr_STColnames).ToArray.Count > 0

If this is true when means there are some columnName difference between two arrays

Cheers @Salman_Fariz

1 Like

Hey bro what about matching two sheets column headers, with same column names, by ignoring an extra column(which is different) in one sheet?.. Is that possible by using above solution?

Hi @Salman_Fariz ,

Yes, the solution given by @Palaniyappan will work here. You can go for it.

Thanks

Yeah instead of reading two excel workbooks we are reading two sheets in same workbook

It’s possible

Just we need to mention the two sheet names in two read range

Cheers @Salman_Fariz