How to change the ordinal or position of the DataColumn to the specified ordinal or position? Is it possible to reorder Columns? If yes, please share a sample script.
Issue/Query: How to change the ordinal or position of the DataColumn to the specified ordinal or position?
- The above scenario is achievable with the help of Set Ordinal method.
Sample Excel/ DataTable Data: Consider the below data
- Launch UiPath Studio and create a sample process.
- Ensure to have UiPath.Excel.Activities installed in Manage packages.
- From the Activities pane, search for Excel application scope/ Read Range (Workbook)/ Read CSV.
- For Illustration, drag 'Excel Application Scope' and 'Read Range' activity to the Designer pane to read the excel file.
- Ensure to set the below parameters:
- Workbook path
- AutoSave (Optional)
- CreateNewFile (Optional)
- Read Only (Optional)
- Visible (Optional)
- AddHeaders (Optional)
- From the Activities pane, search for Invoke method activity and drag the same to the Designer pane.
- Ensure to set the below parameters in property pane of Invoke method activity:
- TagretType: Null
- TargetObject – readRangeOutput.Columns("EmployeePayCheck(in $)")
- MethodName – SetOrdinal
- Expand the Parameter property and set the 'In' parameter to 0 (See below)
Note: 'In' parameter is set based on column Indexing.
- The amended DataTable can now be further used for processing or for writing to Excel.
- To view the amended DataTable, drag 'Output Data Table' activity to the designer pane and set the Input(Datatable) and output (String) parameters.
- Use a Log Message activity/Message Box/Write Line to print the output to the console.