Description
To process an Excel file, it is common 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 for those keywords one by one.
Good news: we have a specific activity to perform that task — it is called For each row.
Still, it may be possible that, for some reason, you are required to execute the steps manually in another workflow. So, here is a quick step-by-step content to guide you throughout this process.
Instructions
First of all, follow these steps:
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"
4. Next, add the Console log activity to print the row values one by one
5. 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)
excel_content[Sheet Name][Row Number][Table Header Name]
6. 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
7. Once done, connect the Assign value to variable activity to the If…then activity so they form a loop
8. Now, run the workflow — you will see the row values getting printed in the console one by one.