如何将 datagrid 表格中的数据导入到 excel 表格中?
如何将datagrid表格中的数据导入到excel表格中?求各位大神帮忙,毕业设计急用。。。。
先引用MicroSoft Excel
Dim xlApp As New Excel.Application, xlBook As New Excel.Workbook, xlSheet As New Excel.Worksheet
Dim Conn As New ADODB.Connection, Rs As New ADODB.Recordset
Rs.Open StrSQL,Conn,1,1 '查询记录
If not Rs.EOF Then
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
For Fld_j = 0 To Rs.Fields.Count - 1
xlSheet.Cells(1, Fld_j + 1) = RsMain.Fields(Fld_j).Name
Next Fld_j
xlSheet.Range("A2").CopyFromRecordset Rs
EndIf
Rs.Close