Unable to Read Range Workbook

I have downloaded this data from a portal and it has two columns that have the same name that is ID. These 2 same IDs are needed hence I cannot deleted one but I can rename one. When I use the read range workbook and it gets there, I get the feedback that: Read Range Workbook: A column named ‘ID’ already belongs to this DataTable.

How do I tackle this?

This is prone to happen as UiPath DataTable cannot contain duplicate column names.
To fix: Read without headers or Rename duplicate header.

Since you need both columns, the solution is to pre-rename the duplicate column header before loading into a DataTable.

Steps to do in UiPath.

  1. Read it without headers and save it to Datatable.
  2. Use invoke code and paste below code .
    Dim usedNames As New HashSet(Of String)(StringComparer.OrdinalIgnoreCase)

For i = 0 To dtRaw.Columns.Count - 1

Dim rawName As String = dtRaw.Rows(0)(i).ToString.Trim

' If blank → give a default name
If String.IsNullOrWhiteSpace(rawName) Then
    rawName = "Column_" & i.ToString
End If

Dim finalName As String = rawName
Dim counter As Integer = 1

' Ensure uniqueness
While usedNames.Contains(finalName)
    finalName = rawName & "_" & counter
    counter += 1
End While

' Rename the column
dtRaw.Columns(i).ColumnName = finalName
usedNames.Add(finalName)

Next

’ Remove header row
dtRaw.Rows.RemoveAt(0)

  1. Map argument in invoke code.

  2. Your new datatable is ready to use now with headers renamed automatically.


    Sequence2.xaml (8.4 KB)

@Baba_Karim_Abdulai

just uncheck headers property and then read the data.

cheers

Hi @Baba_Karim_Abdulai

If this design helped you fix the problem, please mark as solution so it can help others too.