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!!!
Note:
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).
Example
Implementation using UiPath :
Let us implement a workflow which reads an excel file and then we will try to reorder the columns.
Step 1:
Drag “Excel Application Scope” and “Read Range” activities into the design panel to read the excel file and pass the required parameters.
Step 2:
Drag “Invoke Method” activity into the design panel and populate it with the below-mentioned code.
Note:
TargetObject – dt_Sample.Columns(“Country”)
MethodName – SetOrdinal
In Parameter – 0(0 indicates first position ,for our process)
Step 3:
Drag “Output Data Table” activity into the design panel and convert Datatable to String type.
Step 4:
Drag “Message Box” activity into the design panel to display the modified data table.
Step 5:
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…