Activities
latest
false
Banner background image
Productivity Activities
Last updated Apr 15, 2024

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>

      N/A

      totalColumnValues

      IEnumerable<Object>

      N/A

      columnLetter

      Char

      N/A
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. Add a For Each activity underneath the Read Column activity.

    • Insert the variable totalColumnValues in the Values field.
  10. Drag a Write Line activity in the body of the For Each activity.

    • Add the value item.ToString in the Text field.
  11. 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.

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.