|
Function getTestdata( strFilePath,strSheetName,colNumber,flag,parmNumbers)
‘定义变量
Dim ExcelApp,ExcelBook,ExcelSheet,rowcount,colcount,array(),arra(),k
‘创建EXCEL程序,打开工作簿,设置当前活动sheet
Set ExcelApp = CreateObject(“Excel.Application”)
Set ExcelBook = ExcelApp.WorkBooks.Open(strFilePath)
Set ExcelSheet = ExcelBook.WorkSheets(strSheetName)
‘取得EXCEL表共有几行、几列
rowcount=ExcelBook.ActiveSheet.UsedRange.Rows.Count
colcount=ExcelBook.ActiveSheet.UsedRange.Columns.Count
‘确定哪些行的数据需要执行,存在一维数组中
m=0
For i=1 To rowcount
If ExcelSheet.cells(i,colNumber)= flag Then
ReDim PreServe arra(m)
arra(m)=i
m=m+1
End If
Next
‘重定义二纬数组,第一列存放每条测试数据行号,及测试数据的参数
ReDim PreServe array(m-1,parmNumbers)
For i=0 To m-1
array(i,0)=arra(i)
For j=1 To parmNumbers
array(i,j)=ExcelSheet.cells(arra(i),j+colNumber)
Next
Next
‘返回值
getTestdata=array
‘关闭Ecxel
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
End Function
-------------------------------------------------------------------------------------------------------------
Sub setResultByArrdata(strFilePath,strSheetName,arrData,resultColname,arrResult)
Dim ExcelApp,ExcelBook,ExcelSheet,notNullNumber,intCol
‘创建EXCEL程序,打开工作簿,设置当前活动sheet
Set ExcelApp = CreateObject(“Excel.Application”)
Set ExcelBook = ExcelApp.WorkBooks.Open(strFilePath)
Set ExcelSheet = ExcelBook.WorkSheets(strSheetName)
‘取得EXCEL表共有几行、几列
rowcount =ExcelBook.ActiveSheet.UsedRange.Rows.Count
colcount=ExcelBook.ActiveSheet.UsedRange.Columns.Count
intCol =getColByValue(strFilePath,strSheetName,resultColname)
‘统计结果所在的列有多少行不为空
notNullNumber=0
For i=1 To rowcount
If ExcelSheet.cells(i,intCol)“” Then
notNullNumber=notNullNumber+1
End If
Next
If notNullNumber=1 Then
For i=0 To UBound(arrResult)
ExcelSheet.cells(arrData(i,0),intCol).value = arrResult(i)
Next
Else
For i=0 To UBound(arrResult)
ExcelSheet.cells(arrData(i,0),colcount+1).value = arrResult(i)
Next
End If
ExcelApp.DisplayAlerts = false
ExcelApp.Save
closeExcelSheet ExcelBook,ExcelApp,ExcelSheet
End Sub |
|