Quickly import excel to Quicktest

Article Tools

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!

Previous postGenerate a GUID with COM Next postQuickly import excel to Quicktest (Russian Translation)

Related Posts

Post Your Comment

You must be logged in to post a comment.