Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to retrieve data from excel to datatable
#1
Solved: 10 Years, 9 Months ago
Hi,
Please can any one let me know how to retrieve data from excel to datatable?
Regards,
Shwetha
Reply
#2
Solved: 10 Years, 9 Months ago
Hi,

Please find the Code below:

Code:
set objexcel = createobject("Excel.application")
Set objWorkbook = objExcel.WorkBooks.Open("D:\ExcelTest.xls")
Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
cc = objDriverSheet.usedrange.columns.count
rc = objDriverSheet.usedrange.rows.count
for i = 1 to rc
rname = objDriverSheet.cells(i,1).Value
if rname ="TEST_002" then
for j = 2 to cc
fieldvalue = fieldvalue & " " & objDriverSheet.cells(i,j)
next
end if
'End for
next
msgbox fieldvalue

objexcel.quit
Set objexcel=Nothing
Set objDriverSheet=Nothing
Set objWorkbook=Nothing


Also find the attached screenshot of the excel i was using.

Regards,
Mohit


Attached Files Image(s)
   
Reply
#3
Solved: 10 Years, 9 Months ago
Hi Shwetha,

In order to get the datas from excel to QTp datatable, QTp provides import feture...

Use the below code

Datatable.Import "C:\SampleFile.xls","<SheetNameInExcel(SourceSheet)>","<SheetNameIn Datatable(Destination Sheet)>"

please refer to QTp help for more information.

Regards,
Ankesh
Reply
#4
Solved: 10 Years, 9 Months ago
Hi Mohit,
I have created the excel which is attached by you. and copied the same script in QTP. when i run the script it displays error as :

ActiveX component can't create object: 'Excel.application'

Line (1): "set objexcel = createobject("Excel.application")".

Please help me on this.

Regards,
Shwetha
Reply
#5
Solved: 10 Years, 9 Months ago
shwetha, you need to install msoffice in your computer
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error as Global Not defined while trying to retrieve value from Datatable siddharth1609 0 851 09-11-2019, 02:52 PM
Last Post: siddharth1609
  Cannot retrieve Native property JeL 1 914 07-29-2019, 05:41 PM
Last Post: JeL
  Want to read the data from excel and set read value in the JavaTable rajeevk7 0 2,171 07-10-2017, 04:20 PM
Last Post: rajeevk7
  dtLocalSheet empty even though excel file contains data cantorre 2 2,214 05-10-2017, 12:47 PM
Last Post: vidhi
  Reading data from excel sheet serenediva 1 8,849 03-03-2017, 10:07 AM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 1 Guest(s)