注册 登录
Office中国论坛/Access中国论坛 返回首页

的个人空间 http://www.office-cn.net/?0 [收藏] [复制] [分享] [RSS]

日志

导出DataGrid到Excel

已有 1826 次阅读2008-4-26 10:33 |个人分类:Access

'-作者;Grant
'-时间;2008-1-14'-Email;20991943@qq,cin
'-QQ;20991943
'-网站;
www.accessbbs.cn
'-博客;http://www.accessbbs.cn/bbs/blog/?uid/3
'-简介;应网友所求导出DataGrid到Excel

    Dim oExcel As Object
    Dim oBook As Object
    Dim I, J As Integer

    Set Excel = CreateObject("Excel.Application")
    Set Book = oExcel.Workbooks.Add()
    oExcel.Visible = True

    For I = 1 To DataGrid1.Columns.Count
        oBook.Worksheets(1).Cells(1, I) = DataGrid1.Columns(I - 1).Caption
        For J = 0 To DataGrid1.VisibleRows - 1
            oBook.Worksheets(1).Cells(J + 2, I) = DataGrid1.Columns(I - 1).CellText(DataGrid1.RowBookmark(J))
        Next J
    Next I

    Set Book = Nothing
    Set Excel = Nothing

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-25 06:36 , Processed in 0.060871 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部