Delete Column
Verb: deleteColumn
Available from: <Standard>
Deletes a column from a data table, according to the column index or its name.
Syntax
deleteColumn --column(String) [--getbyindex(Boolean)] --dataTable(DataTable)
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--column | Column | Required | Text | Name or index of the column to exclude from the data table. |
--getbyindex | Use Index | Optional | Boolean | When enabled, allows the column to be deleted in the data table from its index. |
--dataTable | Table | Required | Data Table | Data table from which the column is deleted. |
Example
Example 1: The command deletes the column named "City".
defVar --name excelFile --type Excel
defVar --name excelTable --type DataTable
// Download the following file to execute the command
excelOpen --file "tableExcelCompanyCity.xlsx" excelFile=value
excelGetTable --file ${excelFile} --getfirstsheet --entiretable --hasheaders excelTable=value
logMessage --message "Data table before excluding the \"City\" column:\r\n${excelTable}" --type "Info"
//
deleteColumn --column City --dataTable ${excelTable}
logMessage --message "Data table after excluding the \"City\" column:\r\n${excelTable}" --type "Info"
excelClose --file ${excelFile}
// The above example returns the following output:
// Table before deleting "City" column:
// Company City
// IBM Corporation, Toronto
// Microsoft Corporation, São Paulo
// IBM Corporation, Armonk
// Table after deleting "City" column:
// Company
// IBM Corporation
// Microsoft Corporation
// IBM Corporation
Example 2: The command deletes index column 1 from a data table.
defVar --name excelFile --type Excel
defVar --name excelTable --type DataTable
// Download the following file to execute the command
excelOpen --file "tableExcelCompanyCity.xlsx" excelFile=value
excelGetTable --file ${excelFile} --getfirstsheet --entiretable --hasheaders excelTable=value
logMessage --message "Data table before deleting index column \"1\":\r\n${excelTable}" --type "Info"
//
deleteColumn --column 1 --getbyindex --dataTable ${excelTable}
logMessage --message "Data table after deleting index column \"1\":\r\n${excelTable}" --type "Info"
excelClose --file ${excelFile}
// The above example returns the following output:
// Data table before deleting index column "1":
// Company City
// IBM Corporation, Toronto
// Microsoft Corporation, São Paulo
// IBM Corporation, Armonk
//
// Data table after deleting index column "1":
// City
// Toronto
// São Paulo
// Armonk
For the correct operation of the scripts above, it is necessary to download the files and enter their path in the File parameter of the Open Excel File command.
Remarks
When enabling the Use Index parameter, the value used in the Column parameter must be a numeric value.
It is noteworthy that the position of the columns starts at 1.