Then
Reorganize in Below format
(The last character first in numerical ones are sorted and then alphabetical one)
i.e in E_no the last character (1,2,3,a,b,c as below given as example)
1. Use Excel Application Scope to read the data from the Excel file.
2. Use Read Range activity to read the data into a DataTable variable.
3. Use Assign activity to create a new DataTable variable to store the sorted data:
- Use LINQ query to order the rows based on the last character of the 'E_no' column.
- Example LINQ query:
sortedData = dt.AsEnumerable() _
.OrderBy(Function(row) If(Char.IsDigit(row.Field(Of String)("E_no").Last()), 0, 1)) _
.ThenBy(Function(row) row.Field(Of String)("E_no").Last()) _
.CopyToDataTable()
4. Use Write Range activity to write the sorted data back to the Excel file.
Make sure to adjust the column name (‘E_no’) in the code snippet according to the actual column name in your Excel file. This script uses LINQ to sort the data based on the last character as specified in the format.
Also, ensure to handle exceptions and validate the data to ensure it meets the expected format before sorting and writing it back to the Excel file.
Extract the last characters: Use a loop to iterate through the data and extract the last character from each E_no value. Store the extracted characters in a separate list.
Sort the last characters: Sort the list of extracted characters. For numerical characters, sort them in ascending order, and for alphabetical characters, sort them lexicographically.
Reorder the data: Create a new list to store the reorganized data. Use the sorted list of last characters as a reference to determine the order in which to add the corresponding E_no values to the new list.
Update the original data: Replace the original data with the reorganized data.