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)
Dim cls() As String = { "报名号","考试号","姓名","生物","地理","年级代码","班级","学校名称" }
Dim dict As new Dictionary(of String,Integer)
For i As Integer = 0 To cls.Length -1
dict.Add(cls(i),0)
Next
For i As Integer = 0 To sheet.Cols.count -1
If dict.ContainsKey(sheet(0,i).value) Then
dict(sheet(0,i).value) = i
End If
Next
Tables("成绩").StopRedraw()
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bmh1 As String = sheet(n,dict("报名号")).value.replace(" ","").replace(chr(9),"")
Dim xm1 As String = sheet(n,dict("姓名")).value.replace(" ","").replace(chr(9),"")
Dim bj1 As String = sheet(n,dict("班级")).value.replace(" ","").replace(chr(9),"")
Dim njdm1 As String = sheet(n,dict("年级代码")).value.replace(" ","").replace(chr(9),"")
Dim xxmc1 As String = sheet(n,dict("学校名称")).value.replace(" ","").replace(chr(9),"")
Dim dr As DataRow = DataTables("成绩").sqlFind("单位名称 = '" & xxmc1 & "'and 姓名 = '" & xm1 & "'And 考试名称 = '" & "16秋10月考" & "' And 年级代码 = '" & njdm1 & "' And 班级 = '" & bj1 & "'")
If dr Is Nothing Then '如果不存在同考号的行
dr = DataTables("成绩").AddNew()
End If
dr("生物_A") = val(sheet(n,dict("生物")).value)
dr("地理_A") = val(sheet(n,dict("地理")).value)
'dr("报名号") = sheet(n,dict("报名号")).value.replace(" ","").replace(chr(9),"")
'dr("考试号") = sheet(n,dict("考试号")).value.replace(" ","").replace(chr(9),"")
dr.save
Next
Tables("成绩").ResumeRedraw()
'DataTables("成绩").save()
End If