记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

excel采用usedRanage 与jet用select实现单元格访问

上一篇 / 下一篇  2008-05-12 20:08:18 / 个人分类:自动化测试框架与实现

By Wiston Li

在访问excel时,可用如下两种机制来进行单元格的访问遍历,

1,excel采用usedRanage 遍历到二维数组  2,采用jet用select into 到变量中去

二者都是放在内存中,从这两者的实现思路可以看到提高excel的i/o性能的可能着手地方,

代码如下:

1,
tmpArray = ReadExcel  ("d:\devtmp\ADOtest.xls", "join")

For i= 1 to ubound(tmpArray, 1)     ' 输出二维数组
  For j = 1 to ubound(tmpArray, 2)
     msgbox tmp(i,j)
   Next
Next

Function ReadExcel(sFileName,sSheetName)
Dim oExcel
Dim oRange
Dim arrRange

On Error Resume Next
Set ōExcel = CreateObject("Excel.Application")
 oExcel.Workbooks.Open(sFileName)
 Set ōRange = oExcel.Worksheets(sSheetName).UsedRange ' 输出到二维数组中oRange
 If Err.Number <> 0 Then
 ReadExcel = Array("Error")
 msgbox   ReadExcel
 Exit Function
 End If
On Error Goto 0
 
 arrRange = oRange.Value 
 Set ōRange = Nothing
 oExcel.Quit
 Set ōExcel = Nothing
 ReadExcel = arrRange
 
 End Function

 

2, Function xlsGetSpecifiedDataFromDPForParameterbak(sFilePath,  sSheetName, sVarible )

      Dim sConnStr                                     
      Dim oConn                                        
      Dim oRS                                          
      Dim oFSO  
      Dim sSql
      Dim iFirstEnd
      Dim iSecondEnd                                      
      On Error Resume Next
      Set ōFSO = CreateObject("scrīpting.FileSystemObject") ' check the file if exists
     
      If  not  oFSO.FileExists(Trim(sFilePath)) Then   
          MsgBox "No Datapool File Found"
          Exit Function
      End If 
      If Trim(sSheetName)= "" Then  ' check the worksheet if exists
         MsgBox "No Sheet Found"
         Exit Function
      End If
     
      ' create the jet connection and get the DB object
      sConnStr   =  "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &sFilePath  & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""; "
      Set   ōConn =   CreateObject("ADODB.Connection")  
      oConn.Open   sConnStr
      Set ōRS = CreateObject("ADODB.Recordset")
      iFirstEnd=4   ' mark the start flag
      iSecondEnd=1000 ' mark the end flag, but unlimit depend on your requirement
      sSql="Select * from [" &sSheetName & "$A" &iFirstEnd  &":B" & iSecondEnd  &"]"
     
      ' find the data you want to search
      oRS.Open sSql,  oConn
      If Trim(sVarible) <> ""  Then 
        Do   While   Not   oRS.EOF   
                  If Trim(oRS(0)) = "&end&" Then  ' terminal the find until end
                   Exit Do
                  End If
                  
          If trim (oRS(0)) =trim (sVarible) Then
                xlsGetSpecifiedDataFromDPForParameter=oRS(1)
                Exit function
          End If
            oRS.MoveNext   
        Loop 
        Else 
          MsgBox "No data matched"            
      End If 
       
      Set ōConn = nothing
      Set ōRS = nothing
      Set ōFSO = nothing
      If Err.Number <> 0 Then                                                                         
         MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Descrīption & Err.Source)
      End If
      On Error Goto 0
End Function


 


TAG: 自动化测试框架与实现

 

评分:0

我来说两句

日历

« 2024-03-23  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 153046
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar