Sometimes we might be asked to change the order of the columns in the excel and then process the data.
SetOrdinal method can be used to achieve the above.
Let’s see how to use it in the UiPath!!!
1.ColumnName – The name of the column for which we want to change the position.
2.Parameter – To which position or index, we want to move the column to(Indexing starts from zero).
Implementation using UiPath :
Let us implement a workflow which reads an excel file and then we will try to reorder the columns.
Drag “Excel Application Scope” and “Read Range” activities into the design panel to read the excel file and pass the required parameters.
Drag “Invoke Methode” activity into the design panel and populate it with the below-mentioned code.
TargetObject – dt_Sample.Columns(“Country”)
MethodName – SetOrdinal
In Parameter – 0(0 indicates first position ,for our process)
Drag “Output Data Table” activity into the design panel and convert Datatable to String type.
Drag “Message Box” activity into the design panel to display the modified data table.
Finally, let’s run the project.
We can see the modified DataTable with reordered column names!!!
Click here to download the Source Code…
Hope it has helped you…