如何把MsflexGrid里的内容输出到Execel里,希望能具体给一个例子,在线等当中

解决方案 »

  1.   

    Private Sub Command1_Click()
    '导出
        Dim Mrows, Mcols As Integer
        Dim xlApp As Object
        Dim xlWb As Object
        Dim xlWs As Object
        Dim i, j As Long
        Mrows = MSHFlexGrid1.Rows
        Mcols = MSHFlexGrid1.Cols
         
        On Error GoTo err
         
        Set xlApp = CreateObject("Excel.Application")
        Set xlWb = xlApp.Workbooks.Add
        Set xlWs = xlWb.Worksheets("Sheet1")
          
        xlApp.Visible = True
        xlApp.UserControl = True
         
        For i = 1 To Mrows
         For j = 1 To Mcols - 1
           xlWs.Cells(i, j).Value = MSHFlexGrid1.TextMatrix(i - 1, j)
         Next
        Next
         
        xlApp.Selection.CurrentRegion.Columns.AutoFit
        xlApp.Selection.CurrentRegion.Rows.AutoFit
        
        Set xlWs = Nothing
        Set xlWb = Nothing
        Set xlApp = Nothing    Exit Suberr:
        MsgBox "不能导出,请检查是否正确安装了Microsoft Excel", vbExclamation, "LBWU"
    End Sub