Chinaunix首页 | 论坛 | 博客
  • 博客访问: 734821
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:44:34

         '从excel表里读取数据的简单例子
        '$include "sqautil.sbh" '头包含
        Sub Main
        Dim Result As Integer
        dim excel as Object '定义对象
        dim book as Object
        dim worksheet as Object
        dim name1 as String
        dim pass as String
        dim count as Integer
        on error resume next
        Set excel = GetObject("excel.application") '设置excel变量为execl对象
        if(excel Is Nothing) then '判断是否设置成功
        Set excel = CreateObject("excel.application") '创建excel对象
        if(excel Is Nothing) then '判断是否创建成功
        MsgBox "Couldn't find Excel!"
        Exit Sub
        End if
        End if
        Set book = excel.Workbooks.Open("d:\qingd.xls") '打开具体Excel文件,这里是我d盘下一个名为qingd的xls文件
        Set worksheet = book.Worksheets("1") '设置工作的表,工作表的名字为1
        For count=1 To 3 '在excel表里取三行数据
        name1 = worksheet.Cells(count,1).Value '从表中取具体行列对应的值
        'pass = worksheet.Cells(2,1).Value
        msgbox name1
        next count
        excel.Quit '关闭excel
        Set excel = Nothing '把excel对象设置为空
        End Sub
--------------------next---------------------

阅读(418) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~