Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to retrieve data from excel to datatable
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi,
Please can any one let me know how to retrieve data from excel to datatable?
Regards,
Shwetha
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks 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: 11 Years, 3 Months, 4 Weeks 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: 11 Years, 3 Months, 4 Weeks 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: 11 Years, 3 Months, 4 Weeks 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 965 09-11-2019, 02:52 PM
Last Post: siddharth1609
  Cannot retrieve Native property JeL 1 1,087 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,317 07-10-2017, 04:20 PM
Last Post: rajeevk7
  dtLocalSheet empty even though excel file contains data cantorre 2 2,434 05-10-2017, 12:47 PM
Last Post: vidhi
  Reading data from excel sheet serenediva 1 9,621 03-03-2017, 10:07 AM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 3 Guest(s)