Comparing two excel file

excel

#1

Hi,

I have two excel file which is now taken into two different datatable ( dt1 and dt2).
dt2 - is a template where I need to pick the specific value as per the dt1.
dt1- has 63 rows from column 15 I need to start reading the value and check in dt2

|Q1|Q2|Q3|Q4|Q5|Q6|Q7|Q8|Q9|
|— |— |— |— |-- -|-- -|-- -|-- -|—|
|3 | 3| 3| 3| 3| 3| 1| 3| 3|
|3 | 3| 3| 2| 3| 3| 1| 3| 4|

Q.No Q Name 1 2 3 4
Q8 | Bi-Polar| YES | |NO | abc
Q11 | cancer | YES | |NO| efg
Q10 | dialysis | YES | |NO| hij
Q7 |Depression |YES | |NO| klm
Q6 Diabetes | |YES |NO| nop

So in this scenario
I want to compare if Q1 has value 3 then I want to pick Q8 value No (3 means No)

Sorry could not upload files as new users are restricted to upload files
appreciate your help :slight_smile:


#2

So, if I get you correct, you need to loop through dt2, use the “Q.No” as the column in dt1 and use that value as the columnname or index in dt2 to take the value and store in dt1.

psuedocode might look like this:

For each row In dt2
    Assign dt1.Rows(1)(row("Q.No").ToString) = row(dt1.Rows(2)(row("Q.No").ToString)

I’m assuming that in your template, the first row is for the YES, NO, abc, etc

Just to summarize, you can use the values in dt2 as the columnnames in dt1 and vice versa.

I still wasn’t understanding what you needed fully, however.
If you want the Q.Name stored as the columnname, you can change it by doing

Assign dt1.Columns(row("Q.No").ToString).ColumnName = row("Q.Name").ToString

(or store it in another column if preferred)

Hope some of this is helpful.

Regards.


#3

@ClaytonM, Thanks man for writing I wasn’t expecting that I will get response in fraction of seconds.

Yes you are right, I made my query little more complicated.
Lets try again, As you can see dt2 is my template where 1st row is a column. dt2 has column name(Q.No) so if you look at dt1 it has Q1,Q2,Q3…etc
if I find Q1 has 3 value then I will go in dt2 and check Q2 row and take the value of each cell and put it into web form which is very tough for me though I am new to the Uipath unable to understand the logic.
Would appreciate if you can help me out.

regards
Sid


#4

So if you can use a For each row (or generic For each with DataRow typeargument),
you can loop through each row containing the values which you can use to put into the web form. You can also use the first column in dt2 as the columnname in dt1 to pick the right value you want.

You can access each value using for example row(“columnname”).ToString or row.Item(“columnname”).ToString. Alternatively, you can access any row inside a datatable with dt1.Rows(rowindex).Item(“columnname”).ToString

So to put that into some psuedocode, it would look like:

For each row In dt2
    TypeInto row.Item(dt1.Rows(1).Item(row.Item("Q.No").ToString).ToString).ToString

What I did there was in a TypeInto activity I used the values from the datarow.
For the first row, it would look like row.Item("3").ToString or "NO", because dt1.Rows(1).Item(“Q8”).ToString is “3”

I hope this is clear.

Regards.

EDIT: you can also store the value into a variable with an Assign activity before the entering it into the web form, if you prefer.