exce reding with DDT
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
[Hall of Fame]
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help, tristaanogre.
@Naveenks, does the suggestion help your resolve the issue?
Tanya Yatskovskaya
SmartBear Community and Education Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 Yatskovskaya
SmartBear Community and Education Manager
