QTP_Excel Read

来源:互联网 发布:贵阳市小河区淘宝地址 编辑:程序博客网 时间:2024/05/18 23:12

' Core points of this execise:

'1. Open a Excel

'2. Catch row of one sheet

'3. Read each content of sheet

'4. Close and release


Option Explicit 
Dim xlApp,xlWorkBook,xlWorkSheet


'创建Excel应用程序对象
Set xlApp=CreateObject("excel.application")
xlApp.Visible=True


'打开指定的工作簿
Set xlWorkBook=xlApp.Workbooks.Open("c:\testing.xls")

Set xlWorkSheet=xlWorkBook.Sheets("Sheet1")
'获取有效区域的行数和列数
Dim iRowCount,iColumnCount,i,j
iRowCount=xlWorkSheet.UsedRange.Rows.Count
iColumnCount=xlWorkSheet.UsedRange.Columns.Count
For i=1 To iRowCount 
For j=1 To iColumnCount  
MsgBox xlWorkSheet.Cells(i,j)&vbNewLine 
Next 
Next


'关闭工作簿
xlWorkBook.Close


'退出excel程序
xlApp.Quit


'释放excel资源
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
Set xlApp=Nothing

 

原创粉丝点击