TechieClues TechieClues
Updated date Mar 31, 2023
In this article, we will explore the Read Range activity in UiPath and provide a step-by-step guide on how to use it with sample code.
  • 2.7k
  • 0
  • 0

Introduction:

UiPath is a popular Robotic Process Automation (RPA) tool used to automate tedious, repetitive tasks. One of the key features of UiPath is its ability to work with Excel spreadsheets, which are widely used in businesses. The Read Range activity is an important component of the UiPath Excel automation suite, as it allows you to read data from an Excel worksheet and store it in a DataTable variable.

In this article, we will explore the Read Range activity in UiPath and provide a step-by-step guide on how to use it with sample code.

What is Read Range Activity in UiPath?

The Read Range activity in UiPath is a tool that allows you to read data from an Excel spreadsheet and store it in a DataTable variable. The activity can read a single cell, a row, or an entire range of cells. You can use the activity to extract data from Excel worksheets to use in other parts of your UiPath automation project.

How to use Read Range Activity in UiPath?

To use the Read Range activity in UiPath, follow these steps:

Step 1: Drag and drop the Read Range activity

The first step is to add the Read Range activity to your UiPath automation project. Open the UiPath Studio and create a new sequence. From the Activities panel, drag and drop the Read Range activity onto the sequence.

Step 2: Configure the activity

Once you have added the activity to your sequence, you need to configure it. To do this, you need to specify the Excel file path, sheet name, and range of cells to read.

a. Excel file path

The Excel file path is the location of the Excel file you want to read. You can either specify the path directly or use a variable that contains the path. To specify the path directly, click on the "Excel file" field in the Read Range activity and enter the file path in quotation marks. For example, "C:\Users\username\Documents\ExcelFile.xlsx". To use a variable, click on the "Excel file" field and select the variable from the dropdown list.

b. Sheet name

The sheet name is the name of the Excel worksheet you want to read. To specify the sheet name, click on the "SheetName" field in the Read Range activity and enter the name of the sheet in quotation marks. For example, "Sheet1".

c. Range of cells

The range of cells is the cells you want to read from the worksheet. You can either specify a specific range or read the entire worksheet. To read a specific range, click on the "Range" field in the Read Range activity and enter the range in quotation marks. For example, "A1:C10". To read the entire worksheet, leave the "Range" field blank.

Step 3: Add a DataTable variable

The Read Range activity will store the data it reads from the Excel worksheet in a DataTable variable. To use this data in other parts of your automation project, you need to add a DataTable variable to your sequence. To do this, click on the "Variable" tab at the bottom of the UiPath Studio and create a new variable of the DataTable type.

Step 4: Assign the output of the Read Range activity to the DataTable variable

The Read Range activity returns the data it reads as a DataTable variable. To use this data in other parts of your automation project, you need to assign the output of the Read Range activity to the DataTable variable you created in Step 3. To do this, click on the "Output" field in the Read Range activity and select the DataTable variable from the dropdown list.

Step 5: Use the DataTable variable

Now that you have read the data from the Excel worksheet and stored it in a DataTable variable, you can use it in other parts of your automation project. For example, you can use it to populate a form, compare it to another set of data, or export it to another file format.

Here are the steps that demonstrate how to use the Read Range activity in UiPath:

1. Open Excel file

2. Read Range activity: ExcelFilePath = "C:\Users\username\Documents\ExcelFile.xlsx", SheetName = "Sheet1", Range = "A1:C10"

3. Add DataTable variable: DataTable1

4. Assign the output of Read Range activity to DataTable variable: DataTable1 = Output

5. For each row in DataTable1 

6. Message Box: "Name: " + row.Item(0).ToString + ", Age: " + row.Item(1).ToString + ", Gender: " + row.Item(2).ToString 

7. End For 

8. Close Excel file

In this sample code, we first open an Excel file. We then use the Read Range activity to read the data from Sheet1 in the range A1:C10. We add a DataTable variable called DataTable1 and assign the output of the Read Range activity to it. We then use a For Each loop to iterate through each row in the DataTable variable and display a message box with the data for each row. Finally, we close the Excel file.

Conclusion:

The Read Range activity in UiPath is a useful tool for automating Excel tasks. By following the steps outlined in this article, you can easily read data from an Excel worksheet and store it in a DataTable variable for use in other parts of your automation project. With the ability to read a single cell, a row, or an entire range of cells, the Read Range activity provides a flexible solution for working with Excel spreadsheets in UiPath.

ABOUT THE AUTHOR

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

There are no comments. Be the first to comment!!!