Resources

Knowledge Base

Compare DataTables

Compare_data_table_2

To be able to run this example you need to install UiPath.Excel.Activities. See more details on how to install packages:

Task

This sample extract from an Excel file two DataTables and compare each cell from the first DataTable with the corresponding cell of the second DataTable.

Steps to automate

  1. Read Sheet1.
  2. Read Sheet2.
  3. Get the number of columns and rows for each sheet.
  4. Check if both DataTables have the same size.
  5. If their sizes are the same then compare the elements.
  6. In case of identical DataTables display a message like "DataTables have the same information".
  7. Otherwise display a message like "DataTables are different!".

Solution

  1. Read both sheets and convert them into DataTables using "Read Cells Range" activity.
  2. Get the number of columns and rows using the name of the table and ".Rows/Columns.Count".
  3. Use a "FlowDecision" activity to check if both DataTable have the same size.
  4. If their sizes are the same then compare the elements using a "While" activity, a columnIndex and a rowIndex.
  5. Display a message using "Message box" activity to inform the user regarding the result.


Compare_DataTableCompare_DataTable1