Fetch values from an excel sheet cell in QTP

What will be the script to access the values of a particular column of an excel sheet (one by one) and use it ? Pls help..Thanks..

Questions by cyber_coolie

Showing Answers 1 - 9 of 9 Answers

Sycho

  • Dec 17th, 2007
 

To access value from Local Action Sheet of Run Time Data Table, use the following.

Datatable.GetSheet
("Sheet Name").SetCurrentRow("Mention Row Number from where you want to access the value")

Cell_Value = Datatable.GetSheet("Sheet Name").GetParameter("Mentioned Column Name from where you want to access the Value").Value

Msgbox Cell_Value

To access value from Global Data Sheet of Run Time Data Table, use the
following.


Datatable.GlobalSheet.SetCurrentRow("Mention Row Number from where you want to access the value")

Cell_Value = Datatable.GlobalSheet.GetParameter("Mentioned Column Name from where you want to access the Value").Value

Msgbox Cell_Value


CHEERS

CPS

  Was this answer useful?  Yes

Sycho

  • Dec 17th, 2007
 

From Local Sheet
DataTable.GetSheet("SheetName").SetCurrentRow("Enter Row Number")
abc = DataTable.GetSheet("SheetName").GetParameter("Column Name").Value
MsgBox abc


From Global Sheet
DataTable.GlobalSheet.SetCurrentRow("Enter Row Number")
abc = DataTable.GlobalSheet.GetParameter("Column Name").Value
MsgBox abc

  Was this answer useful?  Yes

Hi,

As per my understanding you wanted to fetch the values from external excel sheet.For that you need to create object of that excel application first.Code for this will be like this-

Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.WorkBooks.Open(sWorkBookPath)
Set objDriverSheet = objWorkbook.Worksheets(1)

To check the used row and column count ,use this-

nRowCount =objDriverSheet.UsedRange.rows.Count
nColumnCount =objDriverSheet.UsedRange.columns.Count

To retrieve the cell values of a perticular column
First find out the coulmns you wanted to use

aMandatoryColumnNOs = Split(sMandatoryColumnNOs,";")
'For ArrayNo = 0 to nArraySize
sColumnName = objDriverSheet.cells(1,CSng(aMandatoryColumnNOs(1))).Value
sColumnName = UCase(sColumnName)
  For RowNo = 2 to nRowCount
    sCellValue1 = objDriverSheet.cells(RowNo,CSng(aMandatoryColumnNOs(0))).Value
  Next


At the end you have to close the workbook with

objWorkBook.Close
Set objExcel = Nothing
Set objWorkBook = Nothing
Set objDriverSheet = Nothing

I think this will help.

-Aditya

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions