vb 执行sql语句得到的结果集怎样输出到excel单元格中?
可以,在vb窗口建个datagrid,adodc,用adodc绑定你的数据库,datagrid的DataSource选择那个adodc,这样就能把记录集中的数据显示在datagrid表格中,然后再把datagrid表格中的查询结果导入到Excel中,把datagrid导入到Excel的代码如下:
Dim ex As Object
Dim i As Integer
Dim j As Integer
Dim XlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set XlApp = CreateObject("Excel.Application")
XlApp.Visible = True
Set xlBook = XlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
For i = 0 To DataGrid1.Columns.Count - 1
For j = 0 To DataGrid1.ApproxCount - 1
DataGrid1.Col = i
On Error Resume Next
DataGrid1.Row = j
xlSheet.Cells(j + 1, i + 1) = DataGrid1.Columns.Item(i).Text
Next j
Next i
上述代码可以做进按钮里,记得引用里面添加Excel的dll
望采纳