Dim dlg As new OpenFileDialog
dlg.Filter = "Excel|*.xls;*.xlsx"
If dlg.ShowDialog = DialogResult.OK Then
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("成绩").StopRedraw()
Dim nms() As String = {"学校代码","单位名称","年级代码","班级","学籍号","考号","姓名"}
Dim i As Integer
For i As Integer = 0 To Sheet.Cols.Count -1
If Sheet(0,i).Text = "考号" Then Exit For
Next
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bh As String = sheet(n,i).Text
Dim dr As DataRow = DataTables("成绩").Find("考号 = '" & bh & "'")
If dr Is Nothing Then '如果不存在同考号的行
dr = DataTables("成绩").AddNew()
End If
For m As Integer = 0 To nms.Length - 1
dr(nms(m)) = Sheet(n,m).Value
Next
Next
Tables("成绩").ResumeRedraw()
End If