Sort Table
Verb: sortTable
Available from: <Standard>
Sorts the values of a data table in ascending or descending order using column names.
Syntax
sortTable --orderby(String) --dataTable(DataTable) (DataTable)=value (Numeric)=rows (Numeric)=columns
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--orderby | Order by | Required | Text | Text corresponding to the type of sorting that is used.
1. The syntax used is the column name and the sorting "ASC" or "DESC". 2. You can enter more than one sorting for different columns of the table. Such as: Company ASC, City DESC. |
--dataTable | Data table | Required | Data Table | Data table that should be sorted. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Data table | Data Table | Data table with its values sorted according to the specified sorting. |
rows | Rows | Number | Refers to the number of rows in the table. |
columns | Columns | Number | Refers to the number of columns in the table. |
Example
Sorts the values of a data table specified by the "Company" column, using ascending mode.
defVar --name excelTable --type Excel
defVar --name obtainedExcelTable --type DataTable
defVar --name orderedExcelTable --type DataTable
defVar --name rowsQuantity --type Numeric
defVar --name columnsQuantity --type Numeric
// Import the data table to be used.
// Download the following file to execute the command.
excelOpen --file "tableExcelCompanyCity.xlsx" excelTable=value
excelGetTable --file ${excelTable} --getfirstsheet --entiretable --hasheaders obtainedExcelTable=value
excelClose --file ${excelTable}
logMessage --message "Unordered table: ${obtainedExcelTable}\r\n" --type "Info"
//
sortTable --orderby "Company ASC" --dataTable ${obtainedExcelTable} orderedExcelTable=value rowsQuantity=rows columnsQuantity=columns
logMessage --message "Ordered table: ${orderedExcelTable}\r\nColumns quantity: ${columnsQuantity}\r\nRows quantity: ${rowsQuantity}" --type "Info"
//This example returns the following output:
//Unordered table: IBM Corporation, Toronto
//Microsoft Corporation, São Paulo
//IBM Corporation, Armonk
//
//Ordered table: IBM Corporation, Toronto
//IBM Corporation, Armonk
//Microsoft Corporation, São Paulo
//
//Number of Columns: 2
//Number of Rows: 4
For the correct operation of the above script, it is necessary to download the file and enter its path in the File parameter of the Open Excel File command.