Activities
latest
false
Banner background image
Workflow Activities
Last updated Apr 1, 2024

Remove Data Row/Column

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 in Data Table, and Get Row Item activities. You can find these activities in the package.

This is how the automation process can be built:

  1. Open Studio and create a new Process.
  2. Drag a Sequence container in the Workflow Designer.

    • Create the following variables:

      Variable Name

      Variable Type

      Default Value

      DT1

      DataTable

       

      RemovedRows

      List<DataRow>

      new List(of DataRow)

      StringDT

      String

       
      Note: Add your .xlsx files to the project directory in order to be able to run the entire process from the same place.
  3. 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.
  4. 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.
  5. Drag a For Each Row activity below the Remove Data Column activity.

    • Add the variable DT1 in the DataTable field.
  6. Select the Body container of the For Each Row activity and create the following variables:

    Variable Name

    Variable Type

    Default Value

    Address

    GenericValue

     

    AddressNumber

    Int32

     
  7. 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.
  8. 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.
  9. Add an If activity below the Assign activity.

    • Add the expression AddressNumber >= 10 And AddressNumber <= 50 in the Condition field.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. Add a Write Line activity under the Output Data Table activity.

    • Add the variable StringDT in the Text field.
  15. 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:



Here you can download an example.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.