Is it just me or is there no easy way to open an excel file, and get
the column names that are usually in the 1st row? I would like to be
able to do this for a import tool im writing in vb.net and c#. I need
to be able to list what columns are available in the excel file, so
the user can map these to a ms sql table.
Dim oExcelApp As New Excel.Applicati on()
Dim oWorksheet As Excel.Worksheet
Dim i As Integer = 0
Try
With oExcelApp
.Visible = False
.ScreenUpdating = False
End With
oExcelApp.Workb ooks.Open(FileP ath)
For Each oWorksheet In oExcelApp.Works heets
Debug.WriteLine (oWorksheet.Nam e)
Debug.WriteLine (oWorksheet.Col umns.Count - 1)
For i = 0 To oWorksheet.Colu mns.Count
Debug.WriteLine ("Column " & i & ":" &
oWorksheet.Colu mns.Item(1, i).ToString)
Next
Next
Catch ex As Exception
MsgBox(ex.Messa ge)
Finally
oExcelApp.Workb ooks.Close() : oExcelApp.Quit( )
End Try