datagrid导出excel的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:08:23
使用adodc连接的datagrid,如何导出到excel呢?
感谢

Dim priXLS As Excel.Application
Dim priWorkbook As Excel.Workbook
Dim priSheet As Excel.Worksheet
Dim lngRow, lngRows, intField, intFields, lngID As Long
Set priXLS = New Excel.Application
Set priWorkbook = priXLS.Workbooks.Add
Set priSheet = priXLS.Sheets(1)
With priSheet
intFields = adoRecordset.Fields.Count
For intField = 1 To intFields
.Cells(1, intField) = adoRecordset(intField - 1).Name
Next
adoRecordset.MoveLast
adoRecordset.MoveFirst
For lngID = 1 To adoRecordset.RecordCount
For intField = 1 To intFields
.Cells(lngID + 1, intField) = adoRecordset(intField - 1).Value
Next
adoRecordset.MoveNext
Next
End With
priXLS.Visible = True
Set adoRecordset = Nothing

是要将adoRecordset记录集改为你的就可以了.