注册 登录
编程论坛 VB6论坛

如何将 datagrid 表格中的数据导入到 excel 表格中?

努力的鸭子君 发布于 2014-04-19 14:59, 443 次点击
如何将datagrid表格中的数据导入到excel表格中?求各位大神帮忙,毕业设计急用。。。。
3 回复
#2
owenlu19812014-04-20 16:41
先引用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
#3
w3609894262014-04-20 18:44
第一种
Set excel1 = New Excel.Application
    excel1.Visible = False
    excel1.Workbooks.Open (App.Path & "\程序模版.xls")
    excel1.Workbooks("程序模版.xls").Sheets("发货单").Name = "对账明细"
    excel1.Workbooks("程序模版.xls").Sheets("对账明细").Select
    If excel1.Workbooks("程序模版.xls").ReadOnly = True Then
        excel1.DisplayAlerts = False
        excel1.Application.Quit
        excel1.DisplayAlerts = True
        MsgBox "你已经打开“程序模版.xls”" & Chr(13) & "请关闭原有的“程序模版.xls”。", vbOKOnly + vbExclamation, "错误提示"
        excel1.Visible = True
        Exit Sub
    Else
        excel1.Workbooks("程序模版.xls").Sheets("对账明细").Range("A2").CopyFromRecordset Adodc5.Recordset
    End If
#4
鸥翔鱼游2014-04-28 14:20
看帖是学习,回帖是礼貌。。。
1