sql - 如何将多个查询导出到一个 Excel 工作表中
问题描述
我的 Access 数据库中有一些查询。我知道将这些导出到一个 Excel 工作簿中,但在不同的工作表中。我想将查询结果列出到一张表中,并在结果之间添加一个空行和一个标题。
我不知道我该如何处理它,有人可以帮助我吗?
解决方案
在 Access Vb 编辑器中设置对 Microsoft excel 的引用
Sub ExportQueries
Dim xl as New Excel.Application 'start up excel
dim wb as workbook
dim ws as worksheet
dim r as range
set wb = xl.workbooks.add 'add a workbook
set ws = wb.worksheets(1) 'point to first sheet
set r = ws.range("a1") 'point to a cell
r = "my first caption"
set r = r.offset(1,0)
'dim rs as new recordset 'ADO
Dim rs as recordset 'DAO
' rs.open "myquery",currentproject.connection 'ADO
Set rs = Currentdb.OPenrecordset("myquery") 'DAO
'*************************Copy field headings into excel
Dim f as field
dim x as integer
For each f in rs.Fields
r.offset(0,1)=f.name
x = x+1
next f
set r = r.offset(1,0)
'****************************End field headings
r.copyfromrecordset rs 'copy results into xl
rs.close
set r = r.end(xldown).offset(2,0) 'point to cell 2 below end of first set of results
r = "my next caption"
set r = r.offset(1,0)
rs.open "myotherquery",currentproject.connection
r.copyfromrecordset rs
rs.close
set r = r.end(xldown).offset(2,0)
'and so on
end sub
推荐阅读
- javascript - 欧芹验证器中带有输入键的下一步按钮
- python - Python,使用字典的高效并行操作
- asp.net-core - 如何按实现类型解析服务?
- java - 池中没有可用的连接,netstat 在 Recv-Q 中显示非零值
- ios - tableView 重新加载时崩溃
- driver - 检测并阻止来自驱动程序的 Read/WriteProcessMemory 调用
- dart - built_value 反序列化得到错误“类型'_InternalLinkedHashMap
' 不是类型 'Iterable 的子类型 ' 在类型转换中" - python - 如何在python片段中获取受MERGE查询影响的结果/反馈/行数/行数
- qualcomm - 一切尽在 qualcomm cdb20
- javascript - 深层链接到另一个应用程序,然后回调到同一个浏览器