-
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.
-
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