Login   /   Register

Quickly import excel to Quicktest

Rate this article
     2 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 52 votes, average: 4 out of 5
Loading ... Loading ...
March 30th, 2009 by Yaron Assa

A Russian translate for is article is available here.

Olga Ivolgin gives us a wonderfully useful QTip – quickly import an excel datasheet with the column names!

In automatic testing of big projects always appears requirement for fast "fence" of the data from Excel file in any proper place.

As a rule, the first line contains the name of parameters, and the subsequent lines contain the data for test variations. I offer you a way which for seven seconds will return the necessary data with the names of columns.

Variable="ENV"       
Icount=0  ‘Zeroing items count  
Isheet= "Sheet1"  "’sheet  name 
ExcelPath="D:\LifeInsurance\Excel_Files\Version\30466\OL.xls"
Redim Person(1,0)  "’create a two – dimensional array  
Row=5
 
                                
Call FuncGetValueFromExcellFile(ExcelPath,Isheet,Person,Row,Icount)  "’call   to  function  
 
’search  for   MyValue  in  the  Person  dimensional array  :
  For i=0  to Icount-1
        If Person(0,i)= Variable Then
        MyValue=Person (1,i)
        End If
  Next
  
 
Function FuncGetValueFromExcellFile(ExcelPath,Isheet,Person ,Row,Icount)
 
      Set ExcelObj = CreateObject("Excel.Application")   
      ExcelObj.Workbooks.Open ExcelPath
      Set DetailsSheet = ExcelObj.Sheets.Item(Isheet)    
      
      RowDetals=DetailsSheet.rows(1).Value
      RowDetails2=DetailsSheet.rows(Row).Value
      Set dIcBook=CreateObject("Scripting.Dictionary")
 
       A=dIcBook.RemoveAll   
 
    For j=1 to 256   
        Val1= RowDetals(1,j ) 
        If  Val1=""Then
          ColumnNum=j 
          Exit for
        End If
        Val2=RowDetails2(1,j ) 
       dIcBook.Add Val1 ,Val2
    Next 
 
 ExcelObj.Application.Quit
 Set DetailsSheet = Nothing
 Set ExcelObj = Nothing
 AllKyes = dIcBook.Keys   
 AllItems= dIcBook.Items  
 
 For k=0  to ColumnNum - 2 
             person(0,k) =      AllKyes(k) 
             person(1,k) = AllItems(k)
             Redim preserve person(ubound (person, 1), ubound (person, 2) + 1)
  Next
 
 Icount=dIcBook.count
 A= dIcBook.RemoveAll   
 Set dIcBook=Nothing
 
End Function
 

Thanks Olga for this great QTip!

Posted in MS Applications, MS Office, MS-Excel

4 Responses to “Quickly import excel to Quicktest”

  1. Quickly import excel to Quicktest (Russian Translation) | AdvancedQTP Says:

    [-]

    […] A English translation for is article is available here. […]

  2. naagendra Says:

    [-]

    ok its good and helpful to me.

  3. Murzilka Says:

    [-]

    Senks a large for Olga.
    Very usefully code and helpful to me.

  4. Murzilka Says:

    [-]

    Senks a large for Olga.
    Very usefully code.

Leave a Reply

You must be logged in to post a comment.

This article was viewed 670 times