VBS操作EXCEL
Function initTestCaseDict()
If oTestCaseDictHadInitial <>999 Then
oTestCaseDictHadInitial = 999
Set oTestCaseDict = CreateObject( "Scripting.Dictionary" )
Dim ObjExcel,SrcExcel,keyname,keyValue
filepath = RootDir & "TestPlan.xls"
sheetName = "Plan"
Set ObjExcel = CreateObject ("Excel.Application")
ObjExcel.Visible = False
Set SrcExcel = ObjExcel.WorkBooks.Open(filepath)
SrcExcel.WorkSheets(sheetname).Activate
ifContinue = true
curRow = 2
While ifContinue
ExcValue = SrcExcel.WorkSheets(sheetname).Cells(curRow,1).value
If (ExcValue="") Then
ifContinue = false
ElseIf (ExcValue="√") Then
TestCase_Number = SrcExcel.WorkSheets(sheetname).Cells(curRow,3).value
TestCase_Name = SrcExcel.WorkSheets(sheetname).Cells(curRow,4).value
TestCase_Description= SrcExcel.WorkSheets(sheetname).Cells(curRow,5).value
TestCase_QTPTest = SrcExcel.WorkSheets(sheetname).Cells(curRow,6).value
TestCase_QTPTest = RootDir & "testcase\" & TestCase_QTPTest
TestDataFile= RootDir & "testdata\" & SrcExcel.WorkSheets(sheetname).Cells(curRow,7).value
TestDataSheet= SrcExcel.WorkSheets(sheetname).Cells(curRow,8).value
Dim aCase
aCase=Array(TestCase_Number,TestCase_Name,TestCase_Description,TestCase_QTPTest,TestDataFile,TestDataSheet)
call oTestCaseDict.Add(TestCase_Number,aCase) 'key为用例编号, value是个数组
curRow = curRow+1
Elseif (ExcValue="×") Then
curRow = curRow+1
Else
curRow=curRow+1
End If
SrcExcel.Close
ObjExcel.quit
Set ObjExcel = Nothing
Set SrcExcel = Nothing
End If
End Function