12-03-2012, 03:49 AM
You can import the excel sheet into the data table, here is an example
1 - means: import 1st sheet from the file
....
but the problem with this method is that QTP treats the first row of the file as columns' headers (names),
so you cannot read values from the first row, you can read values only from the second and subsequent rows.
There is another method - you can open the excel file using directly Excel.Application object,
here is an example:
Code:
DataTable.AddSheet("mysheet")
DataTable.ImportSheet "c:\tmp\file.xls", 1, "mysheet"
....
but the problem with this method is that QTP treats the first row of the file as columns' headers (names),
so you cannot read values from the first row, you can read values only from the second and subsequent rows.
There is another method - you can open the excel file using directly Excel.Application object,
here is an example:
Code:
Dim objExcel, objWorkBook
Dim strValue
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = true
Set objWorkBook = objExcel.Workbooks.Open( "c:\tmp\file.xls" )
objExcel.Sheets(1).Select
strValue = objExcel.Cells( 1, 1 ).Value
objWorkBook.Close
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing
MsgBox strValue