Like us on Facebook

June 11, 2015

How to import excel sheet in QTP or UFT during runtime ?

  6/11/2015 No comments

Why do we need to import excel sheet ,when we can make use of in-built data table.
Well,it has always been cumbersome when we deal with large amount of test data.
It become very tough to manage test data in UFT's data table if size of test data
grows or varies all the time.
.. Importing excel sheet into UFT's data table can be done manually but the question
comes to mind that how can we import during run time of script.
We can write a utility function and add it to qfl file of  UFT make the necessary
changes.I'm going to show how can we call a function that can add n number of excel
sheet into your data table during run time.

'####################################################################
'Function Name     : SupLib_ImportSheet
'Description             : Function to import specified Excel sheet into datatable
'Input Parameters : strFilePath, strSheetName
'Return Value             : None
'Author : Vikas
'Date Created : ..
'####################################################################
Function SupLib_ImportSheet(strFilePath, strSheetName)
Datatable.Addsheet strSheetName
Datatable.Importsheet strFilePath, strSheetName, strSheetName
End Function
'###################################################################

In the above code snippet a support library function has been created and named as
SupLib_ImportSheet which accepts two parameters strFilePath and strSheetName.
Parameter strSheetName shall be use to add a new sheet into UFT's data table during
run time.Once a new sheet is created then we can easily import specified excel sheet
from external excel file (remember a excel file consists of n number of sheets) .

I've used ImportSheet method of DataTable object in which we need to pass three
parameters .1st is excel file path,2nd is source sheet name and 3rd is destination sheet
name in UFT's sheet.
Now we can call SupLib_ImportSheet from any action or driver script to add sheet
during run time of script or UFT.

Let me know your suggestion by commenting .

Author: Vikas Pandey

He is a software and web developer working for renowned European investment bank.He loves to share knowledge through blogging whatever he knows and encourages others as well to share the same to make world a better place to live.

0 comments:

.
© 2014-2015 Informational Digit : How-To & Tech Guides. The content is copyrighted to Vikas Pandey and may not be reproduced on other websites. WP themonic converted by Bloggertheme9.
TOP