Results 1 to 2 of 2

Thread: export dbgrid content to excel

  1. #1

    Thread Starter
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    I'm using DBGrid to display data from an access database. Does anyone know how to export the data on the grid to excel? I need to do this from the grid and NOT from the underlying recordset because some fields may be hidden in the grid and I want to just export those fields that are shown...

    Help is much appreciated.

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    There are a couple of ways to do this. There might be a way to do it automatically, but i don't know it.

    You could use an excel object in your application, and insert the values straight into the excel worksheet.

    Alternativley you could produce a comma seperated file, and load that into excel.

    Either way you are going to have to loop through every row-column, and retrieve the value.

    e.g.
    Code:
    'pseudo code.  don't expect this to work!
    
    For i = 1 To iNumOfRows
      For j = 1 To iNumOfCols
        myCSVFile.Write datagrid.row(i).col(j).value & ","
      Next j
      myCSVFile.Writeline
    Next i
    Iain, thats with an i by the way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width