How to change the datatable column sequence


#1

I read excel by using read excel and stored data in datatable, now i want to change the datatable column sequence. Please give solution.


How to reorder columns in datatable
How to do Inter change Columns in excel
How to copy the column content in one excel sheet to the other sheet in the same excel
Insert a Column into a specific position in DataTable
#2

Hi @AmolS,

I believe that in your case you could iterate between those columns and reorder their sequence by using an index array and a for each loop like the example below:


#3

Hey @AmolS

please find this attached sample solution(For demo)customized it as per your need if required and let me know :slight_smile:

Sample Solution.zip (5.9 KB)

Regards…!!
Aksh


How to insert a column between two columns?
Insert column at first position
Insert new columns in excel
#4

Thanks Akshay…!


#5

I edited your code to write the modified data table in the excel sheet. The values are being modified in the same order as in the output panel. But how can I change the column names as well?


#6

Hi @bristighosal910

You can use a simple Assign activity with the following code:
yourDataTable.Columns(0).ColumnName = "New Column Name"
or
yourDataTable.Columns("oldColumnName").ColumnName = "New Column Name"


#7

You can use a simple Assign activity with the following code:

yourDataTable.Columns(0).ColumnName = "New Column Name"

or

yourDataTable.Columns("oldColumnName").ColumnName = "New Column Name"


#8

Okay, thank you.


#9

Thank you.


#10