MSFlexgrid in VB 6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prashantbiyani
    New Member
    • Mar 2007
    • 1

    #1

    MSFlexgrid in VB 6

    Pls tell how i can create Excel sheet in MSFlexgrid & how i write data
  • samycbe
    New Member
    • Feb 2007
    • 83

    #2
    Are you want to export the data from flexgrid to excel or edit data in flexgrid?

    clarify that.......


    samy

    Comment

    • hariharanmca
      Top Contributor
      • Dec 2006
      • 1977

      #3
      Originally posted by prashantbiyani
      Pls tell how i can create Excel sheet in MSFlexgrid & how i write data
      Code:
      'Pass Flx Grid as Perameter to this Method
      Public Sub create_csv(flx As MSHFlexGrid)
          Dim str1 As String
          Dim PrintFormat As String
          'Opening a Csv file
          Open App.Path & "\export.csv" For Output As #1      ' Open file for output.
              'For loop to the count of Grid Rows
              For i = 0 To flx.Rows - 1
                  str1 = ""
                  'For loop to the count of Grid Columns
                  For j = 0 To flx.Cols - 1
                      'Passing Grid Col Value to Temp String Variable
                     str1 = str1 & flx.TextMatrix(i, j) & " "
                     If j <> flx.Cols - 1 Then str1 = str1 & ","
                  Next
                  'Printing Grid Row Value to the Opened Csv format File
                  Print #1, str1
              Next
          'Closing Csv File
          Close #1
          'Passint Grid cols to Format the csv file columns
          openfile (flx.Cols)
      End Sub
      
      Public Sub openfile(thecols As Integer)
          'Decelar Excel Application
          Dim objExcel As New Excel.Application
          Dim objWorkBooks As Object
          Dim objAsheet As Object
          'If Error then Creating Latebinding Object
          If Err.Number Then
              Err.clear
              Set objExcel = CreateObject("Excel.Application")
          End If
          Set objWorkBooks = objExcel.Workbooks
          'Opening File
          objWorkBooks.Open App.Path & "\export.csv", , , 2, , , , , ","
          'Fit the Col Cells to the length of Data
          For intCol = 1 To thecols
              objExcel.Columns(intCol).AutoFormat (2)
              objExcel.Range("a1", (objExcel.Columns(thecols).AddressLocal) & TheRows).AutoFormat (GridStyle)
          Next
          objExcel.Visible = True
      End Sub

      think this will help u

      Comment

      Working...