How to read Excel rows in a loop

To process an Excel file, it is expected that we need to read the row values from a particular column one by one on a loop. For example, imagine you have a column consisting of keywords that you want to input in the browser and extract the search results one by one. We can use the For each row. activity in Studio

Still, it may be possible that, for some reason, you are required to execute the steps manually in another workflow. So, here is some
quick step-by-step content to guide you throughout this process.

Guide

  1. Read the contents of the Excel file using the Read Excel file activity. The values of the Excel file will be stored in the variable “excel_content”
  2. Create a variable called “counter” using the Assign value to variable activity and assign the “0” value to it
  3. Then, use the If…then activity. Bear in mind that:
  • The activities you place below it need to be executed on a loop to read the row data from the variable “excel_content” one by one

  • The conditions provided should be counter < excel_content[“Sheet1”].length

  • The excel_content[“Sheet1”].length returns the highest count of the row from the Excel file

  • The values in the variable “excel_content” are stored as an array, hence you have to start the loop from “counter = 0”

  1. Next, add the Console log activity to print the row values one by one.

  2. Select the “Calculate a value” parameter for the Message option. The syntax to read row-wise data from the Excel file is excel_content[Sheet Name][Row Number][Column Name]. Hence, we must use excel_content[Sheet1][counter][“A”] (keeping in mind that the value of the variable “counter” here is 0).

  3. To loop through each row value, it is essential that we iterate the value of the variable “counter” — that is, we must repeatedly input that value. So, in the Assign value to variable activity that comes after the Console log activity, select the “Variable value” as “Calculate a value” and enter the value counter + 1

  4. Once done, connect the Assign value to variable activity to the If…then activity so they form a loop

  5. Now, run the workflow — you will see the row values getting printed in the console one by one.

Let us know your thoughts below

Happy Automation with ElectroNeek!!!

3 Likes