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 bmh As Integer
Dim ksh As Integer
Dim xm As Integer
Dim sw As Integer
Dim dl As Integer
Dim njdm As Integer
Dim bj As Integer
Dim xxmc As Integer
For i As Integer = 0 To sheet.Cols.count -1
If sheet(0,i).value = "报名号"
bmh =i
End If
If sheet(0,i).value = "考试号"
ksh = i
End If
If sheet(0,i).value = "姓名"
xm = i
End If
If sheet(0,i).value ="生物_A"
sw = i
End If
If sheet(0,i).value ="地理_B"
dl = i
End If
If sheet(0,i).value ="年级代码"
njdm = i
End If
If sheet(0,i).value ="班级"
bj = i
End If
If sheet(0,i).value = "单位名称"
xxmc = i
End If
Next
Tables("成绩").StopRedraw()
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bmh1 As String = sheet(n,bmh).value.replace(" ","").replace(chr(9),"")
Dim xm1 As String = sheet(n,xm).value.replace(" ","").replace(chr(9),"")
Dim bj1 As String = sheet(n,bj).value.replace(" ","").replace(chr(9),"")
Dim njdm1 As String = sheet(n,njdm).value.replace(" ","").replace(chr(9),"")
Dim xxmc1 As String = sheet(n,xxmc).value.replace(" ","").replace(chr(9),"")
Dim ksmc As String = e.Form.controls("combobox2").value
'''' MessageBox.show(bmh1 & xm1 & bj1 & njdm1 & ksmc & xxmc1,"提示")
Dim dr As DataRow = DataTables("成绩").sqlFind("单位名称 = '" & xxmc1 & "'and 姓名 = '" & xm1 & "'And 考试名称 = '" & ksmc & "' And 年级代码 = '" & njdm1 & "' And 班级 = '" & bj1 & "'")
For m As Integer = 0 To sheet.Cols.count -1
If dr Is Nothing Then
dr(sheet(0,m).value) = Sheet(n,m).Value
Else
Continue For
End If
Next
Next
Tables("成绩").ResumeRedraw()
End If
请问老师上面代码是用EXCl 导入生物,地理成绩,注:如果找到符合条件的就把生物、地理成绩导入进行成绩表,否则不增加,再找下一个,出现:未设置对象变量或 With 块变量