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

在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  
上一篇: 设置IFRAME背景透明
下一篇: VisualBasic.NET 基本图片处理函数
文章来自: wwwfaq-it.org
引用通告: 查看所有引用 | 我要引用此文章
Tags: VisualBasic
相关日志:
评论: 0 | 引用: 1 | 查看次数: 6511