51Testing软件测试论坛

标题: 抛砖引玉,共享一个读取Excel表中指定行,指定列的值函数 [打印本页]

作者: dyq    时间: 2008-9-9 16:10
标题: 抛砖引玉,共享一个读取Excel表中指定行,指定列的值函数
此函数封装了一些操作Excel表的操作,这里只作抛砖引玉,与大家一起进步...
Function GetValueFromExcelFile(sFilePath As String, sSheet As String, iRow As Integer, sColumn As String)
         ' sFilePath     type = string   FullPath of the Xls File
         ' sSheet        type = string   Name of the specific sheet
         ' iRow          type = integer  Number of the row for determinate a specific  cell
         ' sColumn       type = string   Letter of the column for determinate a specific  cell

         Dim oExcelObj As Object
         Dim oNewSheet As Object
            
         Set oExcelObj  = CreateObject("Excel.Application")
         oExcelObj.WorkBooks.Open sFilePath
         Set oNewSheet = oExcelObj.Sheets.Item(sSheet )
         GetValueFromExcelFile= oNewSheet.Cells(iRow,sColumn)
         oExcelObj.ActiveWorkBook.save
         Set oNewSheet = Nothing
         oExcelObj.Application.Quit
         Set oExcelObj = Nothing
End Function
sub main
msgbox GetValueFromExcelFile("c:\\123.xls", "InputData", 2, "firstNum")
end sub
作者: bb64844866    时间: 2008-9-18 12:02
标题: 顶下 !
请问Open命令和GetObject()可以同时使用吗?
我的具体代码大致是:
open "C:\aa.xls" for output as #1
close #1
dim excel as object
set excel=getobject("excel.application")
set book=excel.WookBooks.open("c:\aa.xls")
set wooksheet=book.wooksheets("sheet1")
book.wooksheets.cell(1,1)="数据1"
...
set excel=nothing
如果这样写到一起的话,运行结束后,打开这个aa.xls文件,总是提示“无法读取文件”。。。也就是说后面往excel里没有写入任何数据。这个问题该如何解决?




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2