Ask a Question

Returning values from Excel File

TestQA1
Contributor

Returning values from Excel File

Hi,

 

I am new to TC and trying to access/retrieve different cell values through DDT object.

I have the below code, but the result is empty. My Excel structure is : First column has heading username and second column has heading password, rows have data for both columns

 

//USEUNIT A

function DDTReadExcel()
{
var lines = [];

var data = DDT.ExcelDriver(file, sheet); //file and sheet are getting values from UNIT A
while(!data.EOF())
{
var line = {};
for(var i = 0; i < data.ColumnCount; i++)
{
var colName = data.ColumnName(i);
line[colName] = data.Value(colName);
//Log.Message(line[colName])
}
lines.push(line);
data.Next();
}
return lines;
}

 

..................................................

//USEUNIT C

function abc ()
{

var people = DDTReadExcel();
Log.Message(people[1].First);
}

4 REPLIES 4
Marsha_R
Community Hero

I think if you start with the first example listed here, it will be easier for you:

https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/drivers.html

"The following code creates a DDT driver for an Excel sheet, runs through records of the driver’s table and posts values stored in record fields to the test log."

 

 

Some of your code is duplicating what the DDT driver does for you automatically.  Try it and let us know if you get stuck. 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

I can get the column values in the message log, but I cannot get a specific value from a cell. For Example, I need to store (Col1,Row1) value in a variable to use further. 

Hello @TestQA1 

 

I would suggest taking a look at our excel methods they are very easy to work with for pulling Excel data : https://support.smartbear.com/testcomplete/docs/reference/program-objects/excel/index.html

 

Let me know if you have any questions. 

 

Emma

sonya_m
SmartBear Alumni (Retired)

Thanks Community!

 

Hi @TestQA1! Does the recent advice in this thread help?


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: