下面的例子中调用了Excel,需引用microsoft.excel5.0.object library (com)
imports ..
Dim name As String = excelfilePath
Dim objapp As Excel.Application = New Excel.Application()
Dim objsht As Excel.Worksheet = New Excel.Worksheet()
Try
objapp.Workbooks.Open(name)
Catch e As System.Exception
Trace.WriteLine("Error On Open Excel" & e.ToString())
Return False
End Try
objsht = objapp.Worksheets(1)
Dim ds As DataSet = New DataSet()
Dim myTable As DataTable = New DataTable()
Dim myRow As DataRow
Dim rCount, cCount As Integer
Dim i, j As Integer
'''''''''''''''''''''''''''''''''''
'构建数据表
'''''''''''''''''''''''''''''''''''
For i = 1 To objsht.Columns.Count
If objsht.Cells(1, i).value = "" Then
cCount = i - 1
Exit For
End If
Dim column As DataColumn = New DataColumn()
column.DataType = objsht.Cells(1, i).GetType
column.AllowDBNull = False
column.Caption = objsht.Cells(1, i).value
column.ColumnName = objsht.Cells(1, i).value
' Add the column to the table.
myTable.Columns.Add(column)
Next