Forum Discussion

hskim's avatar
hskim
Contributor
8 years ago

How can I search a data in Excel?

Dear,
I use Data-driven loop operation by Excel sheet.

With attached picture, I must use the test data.

 

My problem is the following.

 

If Calumn_A has value of 'A', find same value 'A' in Calumn1(the other sheet) then executing script.
And then search the other A in Calumn1, if has more value 'A', executing script.
And then repeat,..total 4 times.

 

In B case,
If Calumn_A has value of 'B', find same value 'B' in Calumn1.
If the 'B' is it, executing script, and then search value 'B' in Calumn1.
It will be executing script total 2 times.

 

In C case,
If Calumn_C has value of 'C', find same value 'C' in Calumn1.
If the 'C' is it, executing script, and then search value 'C' in Calumn1.
It will be executing script total 3 times.

 

I think this is very complex but I want this can solve by operation in TestComplete.
Please let me know how can I do that.

 

Thank you.
HS Kim

 

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    My suggestion would be to utilize the DDT.ExcelDriver objects to create access to each Excel sheet/tab. It would possibly look something like this.

     

     

    var Driver1, Driver2, Value1, Value2;
    Driver1 = DDT.ExcelDriver("C:\\myfiles\\myexcel1.xls","Sheet1"); while (!Driver1.EOF()) {
    Value1 = Driver1.Value("Calumn_A");
    Driver2 = DDT.ExcelDriver("C:\\myfiles\\test_data.xls","Sheet1");
    while (!Driver2.EOF()){
    Value2 = Driver2.Value("Calumn1");
    if (Value1 = Value2){
    switch (Value1){
    case "A" : RunTestA();
    break;
    case "B" : RunTestB();
    break;
    case "C" : RunTestC();
    break;

    }
    }
    Driver2.Next();
    }
    DDT.CloseDriver(Driver2.Name);
    Driver1.Next();
    }
    DDT.CloseDriver(Driver1.Name);

    This is untested and is completely off the top of my head. But this is what I would at least start with. The idea is that you are looping through your first file. Each time through the loop, you create a driver accessing your second file and loop through it. Each loop through the second file compares the values. If they are the same, run a script based upon the value in the first file. 

     

    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      The only other thing I would suggest is using one Excel workbook and putting the data on different sheets.  We use one workbook for one test to try to keep the number of files we need to track to a minimum.