Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

loops problems

Hello, everyone,

 

The first loop works but the second one not works .

The loop only reads me the first line of my excel table and not the rest why?

 

Thank you for your answers


Flo

winauto.PNG
(102 KB)

Best Answer

Hello Florence,


Regarding your inquiry, since I cannot see how you read the data from Excel, I can give you a general suggestion on how to handle it.


Let's assume that we have the following data in our Excel file.



First we need to read the data using the action "Read from Excel Worksheet" and specify the range of cells we want to read from.

For the data shown above, the action will return a Data Table variable, as shown below.



Then we can loop through the data, using a "For Each" loop. In every iteration of the loop, %CurrentItem% will store the entire data row. For example, in the first iteration of the "For Each" loop, %CurrentItem% will look like this.



Now, in order to access the items in our data row, we have two options. If we want to use specific items we can simply index in %CurrentItem% to do that. For example, %CurrentItem[0]% will give us A1 if the "For Each" loop is in its first iteration, A2 if it's in its second iteration and A3 if it's in its third iteration. If we want to loop through all the items in our data row, we can use a second "For Each" loop, inside the first one, and now %CurrentItem2% will store each individual item so that we can use it however we want.


I hope the above proves to be helpful.

Data Table.PNG
(5.73 KB)
DataRow.PNG
(5.03 KB)

How does your %ExcelData% look?

%ExcelData% is good but I think loop have a problem

But how does the content look?

ADMIN
Answer

Hello Florence,


Regarding your inquiry, since I cannot see how you read the data from Excel, I can give you a general suggestion on how to handle it.


Let's assume that we have the following data in our Excel file.



First we need to read the data using the action "Read from Excel Worksheet" and specify the range of cells we want to read from.

For the data shown above, the action will return a Data Table variable, as shown below.



Then we can loop through the data, using a "For Each" loop. In every iteration of the loop, %CurrentItem% will store the entire data row. For example, in the first iteration of the "For Each" loop, %CurrentItem% will look like this.



Now, in order to access the items in our data row, we have two options. If we want to use specific items we can simply index in %CurrentItem% to do that. For example, %CurrentItem[0]% will give us A1 if the "For Each" loop is in its first iteration, A2 if it's in its second iteration and A3 if it's in its third iteration. If we want to loop through all the items in our data row, we can use a second "For Each" loop, inside the first one, and now %CurrentItem2% will store each individual item so that we can use it however we want.


I hope the above proves to be helpful.

Data Table.PNG
(5.73 KB)
DataRow.PNG
(5.03 KB)
Login or Signup to post a comment