Dim ksmc As String = e.Form.Controls("combobox4").text
If ksmc > ""
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls;*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim s() As String = {"班级全称","姓名","身份证件号","考号","语文_A","语文_B","数学_A","数学_B","英语_A","英语_B","政治_A","政治_B","历史_A","历史_B","物理_A","历史_A","历史_B","生物_A","地理_A"}
Dim Book As New XLS.Book(dlg.filename)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim yb As String =""
For i As Integer=0 To sheet.Cols.count-1
yb = yb & sheet(0,i).text
Next
Dim Lst As New List(Of String)
For j As Integer=0 To s.Length-1
If yb.Contains(s(j)) = False
Lst.add(s(j))
End If
Next
If lst.Count>=1
Dim qn As String
For k As Integer =0 To lst.count-1
qn =qn & vbcrlf & lst(k)
Next
messagebox.show("请注意,你的样表表头没有以下必要字段,或字段标题不正确" & vbcrlf & vbcrlf & qn & vbcrlf & vbcrlf & "请按要求做好样表再重新导入" )
Return
End If
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = sheet.Rows.count -1 '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
Dim nj1 As Integer
Dim bj1 As Integer
Dim xm1 As Integer
Dim sfzjh1 As Integer
For i As Integer = 0 To sheet.Cols.count -1
If sheet(0,i).value = "班级全称"
bj1 =i
End If
If sheet(0,i).value = "姓名"
xm1 = i
End If
If sheet(0,i).value ="身份证件号"
sfzjh1 =i
End If
Next
Dim kh As Integer=0
Dim gf As Integer=0
Dim bgf As String
For n As Integer = 1 To Sheet.Rows.Count -1
If sheet(n,bj1).text.length=0
Else
If sheet(n,bj1).text.Length <= 8 And sheet(n,bj1).text.length>=1
bgf = bgf & vbcrlf & "第" & n+1 & "行"
Else
If left(sheet(n,bj1).text,4)<>"初中20" Or right(sheet(n,bj1).text,1)<>"班"
bgf = bgf & vbcrlf & "第" & n+1 & "行"
End If
gf =gf+1
End If
End If
Next
If gf>=1
messagebox.show("你的表中班级全称列有不规范的记录行" & vbcrlf & bgf & vbcrlf & vbcrlf & "请将有错误的行的班级全称设为:初中20XX级X班的格式并保存后重新导入" )
Return
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If
老师,上面代码上想在导入EXCL前进行一些错误校验,如果有错误则退出改正后再重新导,我现在想法是如果有错则打起选择的EXCL进行改正,如果已打开则该窗口到顶层,这样会少去用户操作步骤,更方便,红色代码不得行没反应,请问该怎么实现