M
murl
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.Application()
Dim oWorksheet As Excel.Worksheet
Dim i As Integer = 0
Try
With oExcelApp
.Visible = False
.ScreenUpdating = False
End With
oExcelApp.Workbooks.Open(FilePath)
For Each oWorksheet In oExcelApp.Worksheets
Debug.WriteLine(oWorksheet.Name)
Debug.WriteLine(oWorksheet.Columns.Count - 1)
For i = 0 To oWorksheet.Columns.Count
Debug.WriteLine("Column " & i & ":" &
oWorksheet.Columns.Item(1, i).ToString)
Next
Next
Catch ex As Exception
MsgBox(ex.Message)
Finally
oExcelApp.Workbooks.Close() : oExcelApp.Quit()
End Try
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.Application()
Dim oWorksheet As Excel.Worksheet
Dim i As Integer = 0
Try
With oExcelApp
.Visible = False
.ScreenUpdating = False
End With
oExcelApp.Workbooks.Open(FilePath)
For Each oWorksheet In oExcelApp.Worksheets
Debug.WriteLine(oWorksheet.Name)
Debug.WriteLine(oWorksheet.Columns.Count - 1)
For i = 0 To oWorksheet.Columns.Count
Debug.WriteLine("Column " & i & ":" &
oWorksheet.Columns.Item(1, i).ToString)
Next
Next
Catch ex As Exception
MsgBox(ex.Message)
Finally
oExcelApp.Workbooks.Close() : oExcelApp.Quit()
End Try