Dim js1 As Integer = Tables("选课数据表").Rows.Count
Forms("主界面").Open()
MainTable = Tables("主界面")
Dim dlg As new OpenFileDialog
dlg.Filter= "Excel文件|*.xls"
If dlg.ShowDialog = DialogResult.OK Then
application.DoEvents
Dim book As new XLS.Book(dlg.FileName)
Dim sheet1 As XLS.Sheet = book.Sheets(0)
Dim bj,xh,xm,km As String
StatusBar.Message1= "正在导入数据,请稍候"
application.DoEvents
If sheet1(2,0).text <> "试卷号" Then
MessageBox.Show("您的数据源不符合国家开放大学报表平台的数据格式,不能导入学生信息表数据!", "提示")
Else
DataTables("选课数据表").StopRedraw
For i As Integer = 1 To sheet1.Rows.count -1
If sheet1(i,0).Text Like "班级*" Then
Dim sts() As String = sheet1(i,0).Text.Split(" ")
bj = sts(0).SubString(3)
xh = sts(3).SubString(3)
xm = sts(6).SubString(3)
km = sheet1(i,5).text
ElseIf sheet1(i,0).text.Length = 4 Then
Dim ksds As DataRow
ksds = DataTables("选课数据表").AddNew()
ksds("学号") = xh
ksds("试卷号") = sheet1(i,0).text
ksds("试卷名称") = sheet1(i,1).text
ksds("考试类型") = sheet1(i,2).text
ksds("考场号") = sheet1(i,3).text
ksds("座位号") = sheet1(i,4).text
ksds("日期") = sheet1(i,5).text
ksds("时间") = sheet1(i,6).text
ksds("是否留考") = sheet1(i,7).text
ksds("是否排考") = "排考"
Dim xhs As List(of String) = DataTables("学生信息表").GetValues("学号")
If xhs.Contains(ksds("学号")) = False Then
ksds.Delete
End If
End If
application.DoEvents
Next
DataTables("选课数据表").ResumeRedraw
End If
End If
With Tables("选课数据表")
For i As Integer = 0 To .Rows.Count - 1
.Rows(i)("起始时间") = Left(.Rows(i)("时间"),5)
.Rows(i)("结束时间") = Right(.Rows(i)("时间"),5)
.Rows(i)("短日期") = Right(.Rows(i)("日期"),2) & "日"
Next
End With
For Each r As Row In Tables("选课数据表").Rows
Dim st As String = r("起始时间")
If st.EndsWith("-") Then
r("起始时间") = "0" & r("起始时间").trim("-")
End If
Next
Tables("选课数据表").sort = "短日期,起始时间,考场号 desc,试卷号,座位号"
For Each r As Row In Tables("选课数据表").rows
Dim dr1 As DataRow = DataTables("学生信息表").find("学号 = '" & r("学号") & "'")
r("姓名") = dr1("姓名")
r("班代码") = dr1("班代码")
r("班名称") = dr1("班名称")
r("班名称中文") = dr1("班名称中文")
r("是否有照片") = dr1("是否有照片")
r("学生类型") = dr1("学生类型")
r("身份证号") = dr1("身份证号")
r("性别") = dr1("性别")
Next
For Each dr As DataRow In DataTables("选课数据表").datarows
dr("照片") = dr("身份证号") & ".jpg"
Next
Dim js2 As Integer = Tables("选课数据表").Rows.Count
Dim js3 As Integer = js2 - js1
For Each rr As Row In Tables("选课数据表").Rows
Dim str1 As String = rr("起始时间")
Dim str2 As String = rr("结束时间")
Dim sp As TimeSpan = cdate("2000-1-1 " & str2) - cdate("2000-1-1 " & str1)
Dim sp1 As String = sp.TotalMinutes
rr("时长") = sp1
Next
Dim sts1 As String = DataTables("学生信息表").GetComboListString("学号","学籍状态 = '毕业'")
sts1 = "('" & sts1.Replace("|","','") & "')"
DataTables("选课数据表").ReplaceFor("是否排考","不排考","学号 in " & sts1)
StatusBar.Message1= "祝贺您!本次共成功导入" & js3 & "科次!"
MessageBox.Show("祝贺您!本次共成功导入" & js3 & "科次!")
Tables("选课数据表").filter = ""
StatusBar.Reset()
我执行这段代码时,当不选择Excel文件时,报下面的错:
此主题相关图片如下:qq截图20150617085235.png
找了半天,不知在哪加判断条件?请专家指点!