KERCHOW 发表于 2014-4-7 12:25:29

请教各位大神,小妹看不懂这两两个函数干什么用的,具体怎么调用?

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

cj_51Testing 发表于 2014-4-8 00:08:43

Function getTestdata( strFilePath,strSheetName,colNumber,flag,parmNumbers)
strFilePath: Excel文件的存放路径
strSheetName: Excel文件中的Sheet名称
colNumber: 列号
flag: 单元格中的值
parmNumbers: 一个数组(全是数字)

array(i,j)=ExcelSheet.cells(arra(i),j+colNumber) 表示这个获取的数据没看懂,这个Excel列有点牛叉呀
返回值是一个2维数组 与flag相关的行号中一些值

cj_51Testing 发表于 2014-4-8 00:15:24

Sub setResultByArrdata(strFilePath,strSheetName,arrData,resultColname,arrResult)
intCol =getColByValue(strFilePath,strSheetName,resultColname)这个函数返回resultColname列号
arrData: 2维数组
resultColname: 单元格值
arrResult: 一维数组
页: [1]
查看完整版本: 请教各位大神,小妹看不懂这两两个函数干什么用的,具体怎么调用?