Web测试

VBS 对EXCEL 操作 的类

上一篇 / 下一篇  2013-02-20 17:02:53 / 个人分类:测试总结

Class Excel
    '****************************************
    '函数功能:获取特定单元格值
    'filepath:文件地址
    'sheetname:表名
    'row:行
    'column:列
    '****************************************
    Function readExcel(filePath,sheetname,row,column)
        Dim excelAPP
        Set excelApp=CreateObject("excel.application")
        excelApp.Workbooks.Open(filePath)
        readExcel=excelApp.Worksheets(sheetname).cells(row,column).value
        excelApp.Quit
        Set excelApp=Nothing
    EndFunction
    
    '****************************************
    '函数功能:在特定单元格写入值
    'filepath:文件地址
    'sheetname:表名
    'row:行
    'column:列
    'str:写入的值
    '****************************************
    Function writeExcel(filePath,sheetname,row,column,str)
        Dim excelAPP
        Set excelApp=CreateObject("excel.application")
        excelApp.Workbooks.Open(filePath)
        excelApp.Worksheets(sheetname).cells(row,column).value=str
        excelApp.Quit
        Set excelApp=Nothing
    EndFunction

    '****************************************
    '函数功能:获取表中被使用的行数
    'filepath:文件地址
    'sheetname:表名
    '****************************************       
    Function rowCount(filePath,sheetname)
        Dim excelAPP
        Set excelApp=CreateObject("excel.application")
        excelApp.Workbooks.Open(filePath)
        rowCount=excelApp.Worksheets(sheetname).UsedRange.Rows.Count
        excelApp.Quit
        Set excelApp=Nothing
    EndFunction

    '****************************************
    '函数功能:获取表中被使用的列数
    'filepath:文件地址
    'sheetname:表名
    '****************************************
    Function columnCount(filePath,sheetname)
        Dim excelAPP
        Set excelApp=CreateObject("excel.application")
        excelApp.Workbooks.Open(filePath)
        columnCount=excelApp.Worksheets(sheetname).UsedRange.columns.Count
        excelApp.Quit
        Set excelApp=Nothing
    EndFunction
EndClass


Function ExcelClass
    Set ExcelClass=New Excel
EndFunction

'QTP10使用DLL在QTP中写代码有智能提示

TAG:

 

评分:0

我来说两句

jing17

jing17

有梦想 有激情 ~@! 放飞无限青春 像鹰一样翱翔 ~#@

日历

« 2024-03-28  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 14980
  • 日志数: 19
  • 建立时间: 2012-05-19
  • 更新时间: 2013-08-18

RSS订阅

Open Toolbar