The example below explains how to remove rows and columns from a DataTable by using the Remove Data Column, Remove Data Row, For Each Row, and Get Row Item activities. You can find these activities in the UiPath.System.Activities package.
This is how the automation process can be built:
- Open Studio and create a new Process.
- Drag a Sequence container in the Workflow Designer.
- Create the following variables:
Variable Name | Variable Type | Default Value |
---|---|---|
| DataTable | |
| List | new List(of DataRow) |
| String |
Note:
Add your
.xlsx
files to the project directory in order to be able to run the entire process from the same place.
- Drag a Read CSV activity inside the Sequence container.
- In the Properties panel, add the expression
"challenge.csv"
in the FilePath field. - Select the Comma option from the Delimiter drop-down list.
- Select the check box for the IncludeColumnNames option.
- Add the variable
DT1
in the DataTable field.
- In the Properties panel, add the expression
- Place a Remove Data Column activity below the Read CSV activity.
- In the Properties panel, add the expression
"Phone Number"
in the ColumnName field. - Add the variable
DT1
in the DataTable field.
- In the Properties panel, add the expression
- Drag a For Each Row activity below the Remove Data Column activity.
- Add the variable
DT1
in the DataTable field.
- Add the variable
- Select the Body container of the For Each Row activity and create the following variables:
Variable Name | Variable Type | Default Value |
---|---|---|
| GenericValue | |
| Int32 |
- Place a Get Row Item activity inside the Body container.
- In the Properties panel, add the expression
"Address"
in the ColumnName field. - Add the value
row
in the Row field. - Add the variable
Address
in the Value field.
- In the Properties panel, add the expression
- Drag an Assign activity underneath the Get Row Item activity.
- Add the variable
AddressNumber
in the To field. - Add the expression
CInt(Address.Split(" "c)(0))
in the Value field.
- Add the variable
- Add an If activity below the Assign activity.
- Add the expression
AddressNumber >= 10 And AddressNumber <= 50
in the Condition field.
- Add the expression
- Drag an Add to Collection activity in the Then field.
- In the Properties panel, add the variable
RemovedRows
in the Collection field. - Add the value
row
in the Item field. - Select the System.Data.DataRow option from the TypeArgument drop-down list.
- Drag a For Each activity below the For Each Row activity.
- In the Properties panel, select the System.Data.DataRow option from the TypeArgument drop-down list.
- Add the variable
RemovedRows
in the Values field.
- Place a Remove Data Row activity inside the Body of the For Each activity.
- In the Properties panel, add the variable
DT1
in the DataTable field. - Add the value
row
in the Row field.
- Drag an Output Data Table activity below the For Each activity.
- In the Properties panel, add the variable
DT1
in the DataTable field. - Add the variable
StringDT
in the Text field.
- Add a Write Line activity under the Output Data Table activity.
- Add the variable
StringDT
in the Text field.
- Run the process. The robot removes the specified fields from the provided table and prints the new DataTable in the Output panel.
- This is how your workflow should look:


Updated 6 months ago