reza_moridi
سه شنبه 25 فروردین 1383, 11:01 صبح
باسلام خدمت کلیه دوستان
من یک grid دارم که اطلاعات یک جدول داخل آن لودشده است حالا میخواهم کلیه این grid رابه نرم افزار excel ارسال کنم اگر کسی میداندمراکمک کندکه حسابی گیرشم
M-Gheibi
پنج شنبه 27 فروردین 1383, 19:18 عصر
من به شخصه برای تبدیل flexgrid به اکسل از این کد استفاده کردم و راضی هم بودم :
Public Sub FlexGrid_To_Excel(TheFlexgrid As MSFlexGrid, TheRows As Integer, TheCols As Integer, _ 
  Optional GridStyle As Integer = 1, Optional WorkSheetName _ 
  As String) 
     
Dim objXL As New Excel.Application 
Dim wbXL As New Excel.Workbook 
Dim wsXL As New Excel.Worksheet 
Dim intRow As Integer ' counter 
Dim intCol As Integer ' counter 
If Not IsObject(objXL) Then 
    MsgBox "You need to have Microsoft Excel installed to use this function", _ 
       vbExclamation, "Haresoftware - Export to Excel Function" 
    Exit Sub 
End If 
'On Error Resume Next is necessary because 
'someone may pass more rows 
'or columns than the flexgrid has 
On Error Resume Next 
' Open Excel 
objXL.Visible = True 
Set wbXL = objXL.Workbooks.Add 
Set wsXL = objXL.ActiveSheet 
' name the worksheet 
With wsXL 
    If Not WorkSheetName = "" Then 
        .Name = WorkSheetName 
    End If 
End With 
     
' fill worksheet 
For intRow = 1 To TheRows 
    For intCol = 1 To TheCols 
        With TheFlexgrid 
            wsXL.Cells(intRow, intCol).Value = _ 
               .TextMatrix(intRow - 1, intCol - 1) & " " 
        End With 
    Next 
Next 
' format the look 
For intCol = 1 To TheCols 
    wsXL.Columns(intCol).AutoFit 
    'wsXL.Columns(intCol).AutoFormat (1) 
    wsXL.Range("a1", Right(wsXL.Columns(TheCols).AddressLocal, 1) & TheRows).AutoFormat GridStyle 
Next 
' Bob's your Uncle! 
End Sub
منبع : http://www.vbcity.com/forums/faq.asp?fid=8&cat=MS%20Excel
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.