|
读excel代码如下
- Function ImportDataSheet(sFileName,sSheetName,sDataTable)
- On Error Resume Next
- Dim excelApp
- Dim excelSheet
- Dim colCount
- Dim rowCount
- Dim param
- DataTable.DeleteSheet sDataTable
- DataTable.AddSheet sDataTable
- Set excelApp = CreateObject("Excel.Application")
- excelApp.workBooks.open(sFileName)
- bSheetExist=False
- For i=1 to excelApp.sheets.Count
- If sSheetName=excelApp.sheets.item(i) Then
- bSheetExist=True
- End If
- Next
- If bSheetExist Then
- Set excelSheet = excelApp.sheets.item(sSheetName)
- colCount = excelSheet.usedRange.columns.count
- For i = 1 to colCount
- param = excelSheet.cells(1,i)
- DataTable.GetSheet(sDataTable).AddParameter param,""
- Next
- rowCount = excelSheet.usedRange.rows.count
- For i = 2 to rowCount
- DataTable.GetSheet(sDataTable).SetCurrentRow i-1
- For j = 1 to colCount
- param = excelSheet.cells(i,j)
- DataTable.Value(j,sDataTable) = param
- Next
- Next
- excelApp.Application.Close
- excelApp.Application.Quit
- Set excelApp=Nothing
- End If
- If err.Number<>0 Then
- excelApp.Application.Close
- excelApp.Application.Quit
- Set excelApp=Nothing
- Call QTPSystemLog("ImportDataSheet",err)
- Err.Clear
- End If
- On Error Goto 0
- End Function
复制代码 各位看看代码有什么错误,问题在于每次执行后进程中仍然会有Excel进程,而且频繁使用taskkill杀死Excel.exe进程,会导致taskkill进程死锁,各位有什么好方法。
请别说使用qtp自带的导入excel方法。 |
|