MSHFlexgrid 컨트롤의 내용을 Excel로 내보내기

1468 단어
        , excel, , , 。
Dim newXls As Excel.Application
    Dim newsheet As Excel.Worksheet
    Dim newBook As Excel.Workbook
    Dim X As Integer
    Dim Y As Integer
    Dim txtSQL As String
    Dim Msgtext As String
    Dim mrc As ADODB.Recordset
    
    txtSQL = "select * from line_info where card_id= '" & Trim(txtCardno.Text) & "'"
    Set mrc = ExecuteSQL(txtSQL, Msgtext)
    
    If mrc.RecordCount = 0 Then
        MsgBox " ", vbOKOnly + vbExclamation, " "
    Else
        Set newXls = CreateObject("excel.Application")
'        Set newsheet = newBook.Worksheets
        
        Set newBook = newXls.Workbooks.Add   ' 
        Set newsheet = newBook.Worksheets(1) ' 
        
        For X = 1 To MyFlexGrid.Rows
            For Y = 1 To MyFlexGrid.Cols
        
                newsheet.Cells(X, Y) = "'" & MyFlexGrid.TextMatrix(X - 1, Y - 1)
            Next Y
        Next X
        
        newXls.Visible = True
        Set newXls = Nothing
      
      End If
      
    
End Sub

이렇게 고칠 필요가 없을 것 같은데, 방법이 아직 많으니, 많은 의견을 제시해 주시기 바랍니다.

좋은 웹페이지 즐겨찾기