Data table first row as header

Hi all,

I have read an excel file and converted in Data table after that I removed first 20 rows from the data table. Now, I need to use first row as header.

Can someone please help me on this? I selected “Add header” while reading the excel file.

Thanks
Naresh

Hi @Naresh_Upadhyay1
dt.Rows.Cast().Take(20).Delete()
Try with this
Or
YourDT.AsEnumerable().Skip(20).CopyToDataTable

1 Like

Hi,@Naresh_Upadhyay1
Can you send the Sample template for reference

@Naresh_Upadhyay1

Please follow the steps

  • Loop the the datatable columns using for each… dt.Columns and type argument ahpuld be system.data.datacolumn
  • Then Assign item.ColumnName = dt.rows(0)(item.ColumnName).ToString this will rename the header
  • After the loop delete the first row

Cheers

Hi @Naresh_Upadhyay1 ,

Could you give this workflow a try?

image

image

AddHeaders.xaml (12.2 KB)

Kind Regards,
Ashwin A.K