'定义字典,通过字典得到table表中的字段与excel表中列的位置的对应关系
Dim zd As New Dictionary(Of String,Integer)
Dim Book As New XLS.Book("C:\我的待办 .xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For Each cl As Col In Tables("代办明细").Cols
For c As Integer = 0 To Sheet.Cols.Count -1 '判断列标题
If Sheet(0, c).Value = cl.Name Then
zd.Add(cl.Name,c)
End If
Next
Next
If zd.ContainsKey("_Identify") = True Then '是否存在
zd.Remove("_Identify")
End If
Tables("代办明细").StopRedraw()
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
Dim r As Row = Tables("代办明细").AddNew()
For Each k As String In zd.Keys '轮询所有的键值
r(k) = Sheet(n,zd(k)).Value
Next
Next
Tables("代办明细").ResumeRedraw()