数据库输出的问题

huangjw 2003-09-12 01:28:49
如何能把数据库access中的一个表的部分字段导出并保存为excel文件。
...全文
39 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zb007 2003-09-22
  • 打赏
  • 举报
回复
up
j4sxw 2003-09-22
  • 打赏
  • 举报
回复
UP
suntt 2003-09-12
  • 打赏
  • 举报
回复
up
stonegoldaustin 2003-09-12
  • 打赏
  • 举报
回复
访问数据库
dim cn as adodb.connection
dim rs as adodb.recordset

set cn = new adodb.connection
cn.ConnectionString = "连接串"
cn.open
set rs = new adodb.recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open "查询语句", cn

输出到excel
Dim xlApplication As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Set xlApplication = New Excel.Application
Set xlWorkBook = xlApplication.Workbooks.Add
Set xlWorkSheet = xlWorkBook.Worksheets(1)
xlApplication.Visible = True
xlApplication.ActiveWindow.DisplayGridlines = False
dim currrow,currcol as long
currrow = 1 : currcol = 1
for i = 0 to rs.fields.count -1
xlworksheet.cells(currrow,currcol) = rs.fields(i).name
currcol = currcol +1
next
currrow = currrow +1 : currcol = 1

do while not rs.eof
for i = 0 to rs.fields.count -1
xlworksheet.cells(currrow,currcol) = rs.fields(i).value
currcol = currcol + 1
next
currrow = currrow +1 : currcol = 1
rs.movenext
loop

Set xlWorkSheet = Nothing
Set xlWorkBook = Nothing
Set xlApplication = Nothing
astroboy 2003-09-12
  • 打赏
  • 举报
回复
用select查询全部的记录集,然后用记录集取字段rs.fields(),
然后写到excel中,用cells(x,y)
就可以了

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧