51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3471|回复: 2
打印 上一主题 下一主题

[原创] vbs读取excel要怎样运行?

[复制链接]
  • TA的每日心情
    郁闷
    2018-11-15 14:58
  • 签到天数: 2 天

    连续签到: 2 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2010-9-9 10:21:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    下面的函数是读取excel的数据,保存后双击脚本,但脚本没有生效,数据都没提取成功,请问这样的脚本要怎样运行?


    function getrowandcol()
      '函数作用:在EXCEL中获取指定字符串存入其它工作表
      '参数说明
      'data:需要查找的字符串
      Dim url,ot,t
      Set excel=CreateObject("Excel.Application")
      set openexcel=excel.Workbooks.Open("D:\工作报告\自动化测试报告\8-10.xls")
      excel.Visible = True
      data = "testurl = http://xg.788111.com"
      j=1
      openexcel.WorkSheets("Sheet1").Activate
      rowcount =openexcel.ActiveSheet.UsedRange.Rows.Count     '获sheet总行数
      Columnscount =openexcel.ActiveSheet.UsedRange.Columns.count '获sheet总列数
        For i=1 to rowcount
                '获取字符串
                    openexcel.WorkSheets("Sheet1").Activate
                    url = openexcel.Cells(i,1).Value
                    ot = openexcel.Cells(i,2).Value
                    t = openexcel.Cells(i,3).Value
            If cstr(openexcel.WorkSheets("Sheet1").Cells(i,1)) = data  then '将EXCEL中数据转化为字符串类型与传入的字符串进行比较
                   openexcel.WorkSheets("Sheet2").Activate
                   openexcel.Columns(1).columnswidth = 20
                   openexcel.Cells(j,1).Value=url
                   openexcel.Cells(j,2).Value=ot
                   openexcel.Cells(j,3).Value=t
                   j=j+1
                    end if
        Next
      openexcel.save
      openexcel.Close                                   
      excel.Quit                                                   
      set  openexcel=nothing      
      Set  excel=nothing
    End Function
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    该用户从未签到

    2#
    发表于 2010-9-9 11:33:47 | 只看该作者
    getrowandcol  这个没返回值?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    郁闷
    2018-11-15 14:58
  • 签到天数: 2 天

    连续签到: 2 天

    [LV.1]测试小兵

    3#
     楼主| 发表于 2010-9-10 09:49:58 | 只看该作者
    是我的原因,谢谢
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-7 20:51 , Processed in 0.089009 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表