Forum Discussion

Azeddin_Margani's avatar
Azeddin_Margani
Contributor
10 years ago

Data-Driven - To read next row of excel sheet.

Hi,

 

I have a scripts which reads data from excel sheet (It contains 3 rows of 1 column). When executed, it completes successfully for the first row but it doesn't continue to the second then third row. My question is,  how to  make it run successfully for the second then the third row.  Do i need a loop so that it runs till no more data?. (i understand loops can be made for keyword scripts!! but not sure if the same can be done for code writen scripts).

 

Your suggestion is much appreciated.

 

Thanks,

A.M.

 

  • I'm guessing you're working in a script and using opening your spreadsheet using COM?

     

    When reading from spreadsheets, I'll usually dump the contents of the sheet into a TC table-variable and then perform my operations from that (so I'm not keeping the sheet locked and am at the mercy of MS Office and network concerns for as little time as possible). Once I have the contents in a TC variable, I'll loop through that as needed. So...

     

    set tblVar = project.variables.tblXLSDump

    for i = 0 to tblVar.rowcount-1

       'do stuff

    next

     

    Hope this helps.

  • NisHera's avatar
    NisHera
    Valued Contributor

    Best way is to use Xl diver comes with TestCompleate as follows

     

    DDT.ExcelDriver("C:\\YourData.xlsx","Sheet01",true);
    do
    {
             YourVariable = DDT.CurrentDriver.Value('Column01');
           //do something with YourVariable
            DDT.CurrentDriver.Next();
    }
    while (!(DDT.CurrentDriver.EOF()));
    DDT.CloseDriver(DDT.CurrentDriver.Name);