在vb中,怎么实现把msflexgrid控件的数据导入excel中,
要求原样导入,有合并的就自动实现合并,
在线等待,最好有源代码

解决方案 »

  1.   

    浏览msflexgrid全部表格,并测试单元格状态,然后填入EXCEL对象
      

  2.   

    Dim xl As Excel.Application
    Dim St As Excel.Worksheet
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim str As StringPrivate Sub Command1_Click()
    Dim i, j
    Set cnn = New ADODB.Connection
    str = "provider=microsoft.jet.oledb.4.0;data source=F:\程序文件\数据库模板\student_choose_course.mdb"
    cnn.Open str
    cnn.CursorLocation = adUseClient
    Set rs = New ADODB.Recordset
    str = "select * from student"
    rs.Open str, cnn, 3, 3Set xl = New Excel.Application
    xl.Workbooks.Open "D:\Documents and Settings\jping lee\桌面\1.xls"
    Set St = xl.ActiveSheet
    i = 0
    j = 0
    rs.MoveFirst
    For i = 0 To rs.RecordCount - 1
        For j = 0 To rs.Fields.Count - 1
            St.Cells(i + 1, j + 1) = rs.Fields(j)
        Next j
        rs.MoveNext
    Next ixl.Visible = False
    xl.Quit
    Set xl = Nothing
    Set St = Nothing
    cnn.Close
    Set rs = Nothing
    End Sub