qtp 读取excel单元格内容

qtp 读取excel单元格内容


Function GetExcelCells(ExcelPath,SheetName,SheetColumn,SheetRow)
 Set ExcelBook = CreateObject("Excel.Application")
 Set ExcelSheet = CreateObject("Excel.Sheet")
 Set myExcelBook = ExcelBook.WorkBooks.Open(ExcelPath)
 Set myExcelSheet = myExcelBook.WorkSheets(SheetName)
 SheetValue = myExcelSheet.cells(SheetColumn,SheetRow).value
 GetExcelCells = SheetValue
 ExcelBook.Quit
 set ExcelSheet = Nothing
 Set ExcelBook = Nothing
End Function

Function GetExcleSheetRowsCount(ExcelPath,SheetName)
 Set ExcelBook = CreateObject("Excel.Application")
 Set ExcelSheet = CreateObject("Excel.Sheet")
 Set myExcelBook = ExcelBook.WorkBooks.Open(ExcelPath)
 Set myExcelSheet = myExcelBook.WorkSheets(SheetName)
 GetExcleSheetRowsCount = myExcelSheet.UsedRange.Rows.Count
 ExcelBook.Quit
 set ExcelSheet = Nothing
 Set ExcelBook = Nothing 
End Function

 

ReadExcelPath="C:\Users\Chengshu\Desktop\CD\混合模型测试框架\文档\001-登录系统.xls"
msgbox  GetExcleSheetRowsCount(ReadExcelPath,"测试用例")
For i=3 to GetExcleSheetRowsCount(ReadExcelPath,"测试用例")
msgbox  GetExcelCells(ReadExcelPath,"测试用例",i,3)
msgbox  GetExcelCells(ReadExcelPath,"测试用例",i,2)
next

posted @ 2014-05-09 17:34  芯树  阅读(622)  评论(0编辑  收藏  举报