Hi,
I have a Acces Db with one Table. The Table has 4 rows (row 1 & 3 are
integer and 2 & 4 are text).
Now i want to export the Table to an Excel workbook.
the next code i used is working (almost) fine.
///Code
'Create a Recordset from all the records in the Orders table.
Dim sNWind As String
Dim conn As New ADODB.Connectio n()
Dim rs As ADODB.Recordset
conn.Open("Prov ider=Microsoft. Jet.OLEDB.4.0;D ata Source=" & _
sNorthwind & ";")
conn.CursorLoca tion = ADODB.CursorLoc ationEnum.adUse Client
rs = conn.Execute("O rders", , ADODB.CommandTy peEnum.adCmdTab le)
'Create a new workbook in Excel.
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("E xcel.Applicatio n")
oBook = oExcel.Workbook s.Add
oSheet = oBook.Worksheet s(1)
'Transfer the field names to Row 1 of the worksheet:
'Note: CopyFromRecords et copies only the data and not the field
' names, so you can transfer the fieldnames by traversing the
' fields collection.
Dim n As Int32
For n = 1 To rs.Fields.Count
oSheet.Cells(1, n).Value = rs.Fields(n - 1).Name
Next
'Transfer the data to Excel.
oSheet.Range("A 2").CopyFromRec ordset(rs)
'Save the workbook and quit Excel.
oBook.SaveAs(sS ampleFolder & "Book3.xls" )
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
'Close the connection
rs.Close()
conn.Close()
///Code
There is one thing that the code does not. And that is, copying the
columnpropertie s(integer, text) to Excel.
Does anyone know how i can acomplish this.
Thanks in advance