标题: 调用vbs脚本 [打印本页] 作者: shuishixingyu 时间: 2009-8-21 18:48 标题: 调用vbs脚本 vbs中函数
Function ReadFile(FileName,SheetName)
Set oExcel = CreateObject("Excel.Application")
Set oSheet = oExcel.WorkSheets(SheetName).UsedRange
Row = oSheet.Cells.Rows.Count
Column = oSheet.Cells.Columns.Count
For i = 1 To Row
For j = 1 To Column
arrRange = oSheet.Cells(i,j).Value
ReadFile = arrRange
Next
Next
oExcel.WorkBooks.Item(1).Close
oExcel.Quit
Set oExcel = Nothing
End Function
在QTP中用arrRange = ReadFile()
msgbox arrRange
如果这么写只能显示Excel中最后一个值,请问有什么办法能在QTP中显示每个遍历到的值?作者: liujinkui 时间: 2009-8-21 21:02
Set oSheet = oExcel.WorkSheets(SheetName).UsedRange
这句是什么意思,我这里运行不了。作者: shuishixingyu 时间: 2009-8-22 10:08
获取表格的使用范围作者: lijinshui 时间: 2009-8-22 10:48
只取出最后一个是当然的呀,之前的都被你覆盖了
Function ReadFile(FileName,SheetName)
Set oExcel = CreateObject("Excel.Application")
Set xlFile = oExcel.WorkBooks.Open(FileName)
Set XlSheet = xlFile.Sheets(SheetName)
Row = XlSheet.usedRange.Rows.Count
Column = XlSheet.usedRange.Columns.Count
For i = 1 To Row
For j = 1 To Column
arrRange = XlSheet.Cells(i,j).Value
msgbox arrRange
ReadFile = arrRange
Next
Next
oExcel.WorkBooks.Item(1).Close
oExcel.Quit
Set oExcel = Nothing
End Function
Dim j, rowcount
Datatable.ImportSheet pathFile,ETableSheet,QTablesheet
rowcount=DataTable.GetSheet(QTablesheet).GetRowCount '返回数据行数
importExcel=rowcount
End Function
ReadFile "E:\1.xls","Global"
msgbox str1
Function ReadFile(FileName,SheetName)
Set oExcel = CreateObject("Excel.Application")
Set oFile= oExcel.Workbooks.Open (FileName)
Set oSheet = oFile.WorkSheets(SheetName).UsedRange
Row = oSheet.Cells.Rows.Count
Column = oSheet.Cells.Columns.Count
For i = 1 To 5
For j = 1 To 10
arrRange = oSheet.Cells(i,j).Value
fileArray(i,j) = arrRange
str1 =str1&i&j&fileArray(i,j)&" " '将搜索到的数据全部显示出来
Next
Next
oExcel.WorkBooks.Close
oExcel.Quit
Set oExcel = Nothing
End Function