Dim dlg As new OpenFileDialog dlg.MultiSelect = True If dlg.ShowDialog = DialogResult.OK Then For Each f As String In dlg.FileNames Dim Book As New XLS.Book(f) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim dic As new Dictionary(Of String, Integer) For i As Integer = 0 To sheet.Cols.Count - 1 If sheet(0,i).Text <> Nothing dic.Add(sheet(0,i).Text,i) End If Next For n As Integer = 1 To Sheet.Rows.Count -1 Dim filter As String = "入住时间 = #" & sheet(n, dic("入住时间")).Text & "# and 姓名 = '" & sheet(n, dic("姓名")).Text & "' and 房间号 = '" & sheet(n, dic("房间号")).Text & "'" Dim dr As DataRow = DataTables("表A").find(filter) If dr Is Nothing Then dr = DataTables("表A").AddNew For Each c As String In dic.Keys If DataTables("表A").datacols.Contains(c) Then dr(c) = sheet(n, dic(c)).Text End If Next Next Next End If
|