Retrieve Xls file data

上一篇 / 下一篇  2008-06-03 13:58:47 / 个人分类:QTP脚本

'Returns a two dimentional array with the excel data
Function GetExcelData(sFileName, sSheetName)
   
Dim oExcel 'The excel's COM object
   
Dim arrRange 'The retrieved data
   
On Error Resume Next
   
Set ōExcel = CreateObject("Excel.Application")
   
If err.Number <> 0 Then
     
MsgBox "Can't Initiate excel." & vbCrLf & _
         
"This operation requires MS excel to be installed.", vbCritical
     
Exit Function
   
End If
   
On Error Goto 0
   
On Error Resume Next
   oExcel.Workbooks.
Open(sFileName)
   
If err.Number <> 0 Then
     
MsgBox "Can't load excel file." & vbCrLf & _
         
"Make sure the file name is correct", vbCritical
     
Exit Function
   
End If
   
On Error Goto 0
   
'Open the sheet and extract the data
   
Set ōSheet = oExcel.Worksheets(sSheetName).UsedRange
   
Set ōRange = oSheet.Range("A1:Z1000")
   
'Cast excel data into a two-dimentional array
   arrRange = oRange.
Value
   oExcel.WorkBooks.Item(
1).Close
   oExcel.Quit
   
Set ōExcel = Nothing
   GetExcelData = arrRange
End Function


TAG: QTP脚本

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-07  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 2112
  • 日志数: 3
  • 建立时间: 2008-04-25
  • 更新时间: 2008-06-03

RSS订阅

Open Toolbar