当前位置:首页 > 网络编程 > 数据库 > ACCESS > 如何在VB程序设计中,将查询结果直接生成表EXCEL表格?

如何在VB程序设计中,将查询结果直接生成表EXCEL表格?

点击次数:58 次 发布日期:2008-11-27 18:43:59 作者:源代码网
源代码网推荐

源代码网整理以下 如何在VB程序设计中,将查询结果直接生成表EXCEL表格?
---------------------------------------------------------------

"傻瓜方式导入
Dim xlApp,xlBook,xlSheet,rows,table,r,c
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = false
Set xlbook = xlapp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
dim strsql as string
strsql="select * from tablename"
dim rs as new adodb.recordset
dim conn as adodb.connection
dim strconn as string
strconn="连结字串你自己写"
conn.open strconn
rs.open strsql,conn,1,1
dim fid as field
dim i as long,i1 as long 
do until rs.eof
for i =0 to rs.fields.count-1
xlSheet.Cells(i1+1, i+1) =rs(i)  
next i
i1=i1+1
loop
for c=0 to column-1
xlSheet.Columns(c+1).EntireColumn.AutoFit
next
xlapp.visible=true


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华