Posts: 54
Threads: 30
Joined: Jul 2008
Reputation:
0
01-26-2011, 01:09 PM
Hi all
I need to retrieve test data from an Excel sheet instead of using the build in Data table. For each iteration passed, i also need to return an "OK" to the Excel sheet.
Could anyone tell me how that is done ?
Posts: 350
Threads: 2
Joined: Mar 2008
Reputation:
0
01-27-2011, 12:09 AM
Hi,
Search for "Excel COM" in this forum.
You can do it easily.
Posts: 54
Threads: 30
Joined: Jul 2008
Reputation:
0
01-27-2011, 05:43 PM
Searched all over this forum and found lots of bits of code which required that you knew the rest of the code.
I want to be more specific about my question
I have an Excel file called: testdata.xlsx in the folder "C:\temp"
In this file I have a sheet called "release 1". In the sheet I have 3 columns which looks as follows:
Column A: UserID
Column B: FirstName
Column C: LastName
In my web application, I have 3 WebEdit fields also called UserID, FirstName and LastName
So how should the code look like if I want to retrieve the data from the 3 columns in Excel and populate the WebEdit's in my web application ?
Posts: 37
Threads: 0
Joined: Jan 2011
Reputation:
0
01-27-2011, 10:31 PM
first you need to change the excel to 2003 format as QTP does not support 2007 format.
then you can use Datatable.importsheet or datatable.import statements to import the sheet to your test. The second way is to change the "Resource" settings for the test (right click on test in test flow tab and select settings), under the data table options give the path of your excel file.
Hope this helps
Posts: 54
Threads: 30
Joined: Jul 2008
Reputation:
0
01-28-2011, 12:53 PM
Thx for your reply, but wont it just take the first row of data ? The next run should fetch data from the second row and so on.
Posts: 37
Threads: 0
Joined: Jan 2011
Reputation:
0
01-28-2011, 08:53 PM
Use the statement
DataTable.ImportSheet SheetPath, SheetSource, Sheetdestination statement in your QTP code to import the excel sheet to your test case e.g.
DataTable.ImportSheet "c:\test.xls","TestData","Login"
This statement will import data from TestData worksheet of test.xls excel sheet to data table of Login action. if you want to import to global sheet then use
DataTable.Import "c:\test.xls"
Posts: 5
Threads: 1
Joined: Jan 2011
Reputation:
0
01-31-2011, 11:05 PM
Don't mean to hijack your thread, but I also have an excel question.
I'm trying to get QTP to read "0002" from my spreadsheet but I'm not sure how to do it.
When I used .csv with a different application it saves the zeros but with .xls it does not seem to be able to.
Thanks!
Posts: 37
Threads: 0
Joined: Jan 2011
Reputation:
0
02-01-2011, 09:34 PM
When you are saving data to excel sheet try to "'" before the data