Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

I need to get data from database and store in Excel

This is a discussion on I need to get data from database and store in Excel within the QTP forums, part of the Software Testing category; I need to get some data from data base and store this (retrieved) data in a excel sheet using VB script in QTP 9.0 I have created connection for data ...

Go Back   Geeks Talk > Software Testing > QTP
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 07-31-2007
Junior Member
 
Join Date: Nov 2005
Location: Hyderabad
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
shyam_meghansh is on a distinguished road
I need to get data from database and store in Excel

I need to get some data from data base and store this (retrieved) data in a excel sheet using VB script in QTP 9.0 I have created connection for data base I have created as excels sheet by using Set XL=CreateObject("Excel.Application") XLworksheet.cells(1,1).value= rs.fields.item("<>")

I have taken a for loop and changed the cells values (1 as i and another 1 as j) But still I am not able to get Plz kindly tell me know this .

I am not getting this
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007
Junior Member
 
Join Date: Jul 2007
Location: Forest Hills, NY
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
adisgee is on a distinguished road
Lightbulb Re: I need to get data from database and store in Excel

Hi, try to use from some of the code below. Will help you navigate through excel. This should help. ' create an invisible instance of an excel object set objexcel = createobject("excel.application") ' open the excel work book ' open (path, confirmconversations, readonly) objexcel.workbooks.open vpath, false, false ' get teh count for the number of worksheets in the excel workbook vworksheetcount = objexcel.worksheets.count ' currently let us work only with the first sheet set currworksheet = objexcel.activeworkbook.worksheets(1) ' set the object to access the excel sheet cells set cells = currworksheet.cells ' get the name of the worksheet vcurrworksheetname = currworksheet.name ' get the rows count and get the columns count vusedcolcnt = currworksheet.usedrange.columns.count vusedrowcnt = currworksheet.usedrange.rows.count ' topmost row used and leftmost column used vsheettop = currworksheet.usedrange.row vsheetleft = currworksheet.usedrange.column ' display the worksheet information, that is being accessed wscript.echo "excel workbook under process = " & vpath & vbcr & vblf & " no of worksheets = " &vworksheetcount & _ vbcr & vblf & "sheet name = " &vcurrworksheetname & _ vbcr & vblf & "used col count # = " &vusedcolcnt & _ vbcr & vblf & "used row count # = " &vusedrowcnt & _ vbcr & vblf & "sheets top most row # = " &vsheettop & _ vbcr & vblf & "sheets left most column # = " &vsheetleft ' loop through each row in the worksheet for vrowctr = 0 to vusedrowcnt - 1 ' loop throuhg each column for vcolctr = 0 to vusedcolcnt - 1 ' get the row that is in the used range currrow = vrowctr + vsheettop ' get the column that is in the used range currcol = vcolctr + vsheetleft ' get the cell value by accessing the row and column vcellcontent = cells(currrow,currcol).value ' display the content wscript.echo "row# " &currrow & " column# " &currcol & _ vbcr + vblf + "cell content is " & vcellcontent next next ' release the cells object memory set cells = nothing ' set the currworksheets object to nothing - release resources set currworksheet = nothing ' close and quit the excel workbook objexcel.workbooks.close objexcel.quit ' set the excel object to nothing set objexcel = nothing ' ---- end of code ---------- ' to write the values simply use: ' cells(currrow,currcol).value = vvaluetowrite ---------------- hope this helps, u can always try out this using wsh and then implement in the qtp action. Njoy, aditya.
Reply With Quote
  #3 (permalink)  
Old 08-06-2007
Junior Member
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 2 Times in 2 Posts
praveenchandupatla is on a distinguished road
Re: I need to get data from database and store in Excel

I have a drop down box to show selected number of records in result page.It contains 4 items like 10, 25,50 and 100. when i was recordes script for seelcting each item and checking selecting number of records in the result page( it is in the same page in the table format)it is generating a new page with same controls( objects) in the OR. how to avaid these in OR? is it possible to write DP for only these lines?, remaining(remaingin lines of code) objects i want use from OR only.

One more problemis if change ( add /remove properties of an OBJECT in OR , my ( recorded )application is not running.
Reply With Quote
The Following User Says Thank You to praveenchandupatla For This Useful Post:
  #4 (permalink)  
Old 08-06-2007
Contributing Member
 
Join Date: Feb 2006
Location: Beverly, Boston
Posts: 43
Thanks: 1
Thanked 1 Time in 1 Post
smartarun is on a distinguished road
Thumbs up Re: I need to get data from database and store in Excel

Use database connection to get connected to database - table. Then making use of database functions get data and store into the variable. Then start assigning the variable value to the respective columns into excel sheet. Strval = datatable.value("table name",db)
*check for correct syntax. If excelfile <> "" then bfoundpath = gettestdatapath(excelfile, strfullpath) if bfoundpath then datatable.import(strfullpath) else exitrun(0) end if
end if ncount = datatable.getsheet("global").getrowcount
datatable.setcurrentrow(1)
i = 1
while i <= ncount datatable.value("column name", "global") = strval
wend similar to above example you can write as many as values you need to store into excel. Arun

Last edited by smartarun; 08-06-2007 at 10:24 PM.
Reply With Quote
Reply

  Geeks Talk > Software Testing > QTP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
reading data from excel sheet in QTP JobHelper QTP 12 3 Weeks Ago 09:46 AM
How to store without using sessions, cookies or any database ravi3679 ASP.NET 13 02-08-2009 11:29 AM
Save Excel file using JDBC into a database supari Java 1 08-30-2007 08:56 AM
All My Software is a password protected database that enables you to store software r JobHelper Geeks Lounge 0 01-05-2007 02:20 PM
Code for getting data from excel sheet JobHelper WinRunner 0 12-20-2006 07:08 PM


All times are GMT -4. The time now is 04:50 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved