Micro Focus QTP (UFT) Forums
Reading data from excel sheet - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Reading data from excel sheet (/Thread-Reading-data-from-excel-sheet)



Reading data from excel sheet - serenediva - 02-23-2017

Hi,

I need a script which can read data from an excel file( where the data is already given) and give the same inputs in a windows application.Is it possible to import the data from the excel sheet without using Datatable.importsheet statement ?? Please help Smile


RE: Reading data from excel sheet - vinod123 - 03-03-2017

⇒Read the data from Excel File:
Code:
Set myxl = createobject("excel.application")

'Make sure that you have created an excel file before exeuting the script.
'Use the path of excel file in the below code
'Also make sure that your excel file is in Closed state
myxl.Workbooks.Open "D:\qtp.xls"

myxl.Application.Visible = true

'this is the name of  Sheet  in Excel file "qtp.xls"   where data needs to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")

'Get the max row occupied in the excel file
Row=mysheet.UsedRange.Rows.Count

'Get the max column occupied in the excel file
Col=mysheet.UsedRange.columns.count

'To read the data from the entire Excel file
For  i= 1 to Row
    For j=1 to Col
        Msgbox  mysheet.cells(i,j).value
    Next
Next

'Save the Workbook
myxl.ActiveWorkbook.Save

'Close the Workbook
myxl.ActiveWorkbook.Close

'Close Excel
myxl.Application.Quit

Set mysheet =nothing
Set myxl = nothing