UiPath Activities

Read from Excel files

The example below explains how to read information from a row or a column, inside an .xlsx file. It presents activities such as Read Row and Read Column. You can find these activities in the UiPath.Excel.Activities package.

This is how the automation process can be built:

  1. Open Studio and create a new Process named by default Main.
  2. Drag a Sequence container in the Workflow Designer.
    • Create a variable named totalColumnIndex of type Int32 and with the Default value of 0.
  3. Place an Excel Application Scope inside the body of the sequence.
    • Add the following path "read_col_row_example.xls" in the WorkbookPath field.
    • In the Properties panel, select the check boxes for the AutoSave, CreateNewFile and Visible options. The robot is now allowed to create a new Excel workbook, to automatically save all the changes made to it and to open the Excel file in the foreground while performing actions on it.
  4. The Excel Application Scope includes a Do sequence. Select the sequence.
    • Create the following variables:
Variable Name
Variable Type
Default Value

firstRowValue

IEnumerable<Object>

-

totalColumnValues

IEnumerable<Object>

-

columnLetter

Char

-

  1. Add a Read Row activity inside the Do sequence.
    • In the Properties panel, add the name of the sheet "SalesOrders" in the SheetName field. Add the value "A1" in the StartingCell field and the variable firstRowValues in the Result field.
  2. Drag an Assign activity below the Read Row activity.
    • Add the variable totalColumnIndex in the To column and the value array.IndexOf(firstRowValues.ToArray.Cast(of string).ToArray, "Total") in the Value field.
  3. Add another Assign activity right below the previous one.
    • Insert the variable columnLetter in the To field and the value convert.ToChar(totalColumnIndex + 65) in the Value field.
  4. Place an Excel Read Column activity under the Assign activity.
    • In the Properties panel, add the name of the sheet "SalesOrders" in the SheetName field, add the value columnLetter + "2" in the StartingCell field and the variable totalColumnValues in the Result field, as output.
  5. Add a For Each activity underneath the Read Column activity.
    • Insert the variable totalColumnValues in the Values field.
  6. Drag a Write Line activity in the body of the For Each activity.
    • Add the value item.ToString in the Text field.
  7. Run the process. The robot reads the first row of the excel file, which is considered the header, computes the index of the Total column, reads it, and logs the values in the console.
     
     
    Download example

Updated 5 months ago


Read from Excel files


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.