cancel
Showing results for 
Search instead for 
Did you mean: 

exce reding with DDT

SOLVED
Highlighted
Contributor

exce reding with DDT

Hi,

 

I wrote a script in DDT to read rows and columns from excel sheet but it is displaying only two even after my sheet having more than 2 rows.:-

 

var RecNo;

 

// Posts data to the log (helper routine)

function ProcessData()

{

  var i;

 

 

 

  for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)

  Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));

  Log.PopLogFolder();

  RecNo = RecNo + 1;

}

 

// Creates the driver (main routine)

function TestDriver()

{

  var Driver;

 

  

  Driver = DDT.ExcelDriver("C:\\Users\\naveenks\\Documents\\ExcelRead.xlsx", "Test");

 

  // Iterates through records

  RecNo = 0;

  while (! Driver.EOF() )

  {

    ProcessData(); // Processes data

    Driver.Next(); // Goes to the next record

  }

 

  // Closes the driver

  DDT.CloseDriver(Driver.Name);

}

 

 

Regards,

Naveen

1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: exce reding with DDT

Thanks for the reply, @Naveenks. As tristaanogre mentioned, it's worth adding your excel file here (or at least a sample to demonstrate the data structure) with the image of the log you get.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

4 REPLIES 4
Community Hero

Re: exce reding with DDT

It would be helpful to see the Excel file you're using.

 

Also, your for loop in ProcessData doesn't have any braces around the code to be executed.  The way it looks now, it will only get the first column and that's all.

 

Finally, your increment of the record number needs to be inside the while loop, not the for loop, so it actually tracks the number of records.

 

I've attached my Excel file and here's the slightly modified code

 

var RecNo;
// Posts data to the log (helper routine)

function ProcessData(){
    var i;
    for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++){
        Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
        Log.PopLogFolder();
    }
}

// Creates the driver (main routine)
function TestDriver(){
    var Driver;
    Driver = DDT.ExcelDriver("C:\\Temp\\Test.xls", "Test", true);
    // Iterates through records
    RecNo = 0;
    while (!Driver.EOF()){
        ProcessData(); // Processes data
        Driver.Next(); // Goes to the next record
        RecNo = RecNo + 1;
    }
    // Closes the driver
    DDT.CloseDriver(Driver.Name);
}

Here's what the log looks like
2019-07-11 08_37_36-Clipboard.png

So, as you can see, on principle, your code works.  But it needed a bit of refinement to actually do what you wanted it to do.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Community Manager

Re: exce reding with DDT

Thanks for the help, tristaanogre.

@Naveenks, does the suggestion help your resolve the issue?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: exce reding with DDT

Hi,

 

I tried with same code but my log is not showing Column no in left pane,instead it is displaying data repeatedly of the row's in column no field.

 

Regards,

Naveen...

Community Manager

Re: exce reding with DDT

Thanks for the reply, @Naveenks. As tristaanogre mentioned, it's worth adding your excel file here (or at least a sample to demonstrate the data structure) with the image of the log you get.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post