删除列
动词:deleteColumn
可从以下位置获取: <Standard>
根据列的索引或名称从数据表删除列。
语法
deleteColumn --column(String) [--getbyindex(Boolean)] --dataTable(DataTable)
输入
| 脚本 | 设计器 | 必需的 | AcceptedTypes | Description |
|---|---|---|---|---|
| --column | 列 | 必需的 | 文本 | 要从数据表排除的列的名称或索引。 |
| --getbyindex | 使用索引 | 可选 | BOOLEAN | 启用后,将允许在数据表中从列索引删除该列。 |
| --dataTable | 表 | 必需的 | 数据表 | 从中删除列的数据表。 |
示例
示例 1:使用该命令删除名为“城市”的列。
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
示例 2:使用该命令从数据表删除索引列 1。
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
对于以上脚本的正确操作,需要下载这些文件并在打开 Excel 文件命令的文件参数中输入其路径。
备注
启用使用索引参数后,在列参数中使用的值必须为数字值。
需要注意的是,列的位置从 1 开始。