无语,你做的例子根本就没有问题,根本就不需要处理。
Forms("主界面").Open()
MainTable = Tables("主界面")
Dim dlg As new OpenFileDialog
dlg.Filter= "Excel文件|*.xls"
If dlg.ShowDialog = DialogResult.Ok Then
Dim xh,sjh,rq1,rq,sj,js,zwh As String
application.DoEvents
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
StatusBar.Message1= "正在导入数据,请稍候"
StatusBar.ProgressBar.Maximum = sheet.Rows.Count
StatusBar.ProgressBar.Minimum = 0
StatusBar.ProgressBar.Visible =True
application.DoEvents
If sheet(0,0).text <> "机考安排表" Or sheet(2,0).text <> "姓名" Or sheet(2,1).text <> "学号" Or sheet(2,2).text <> "试卷号" Or sheet(2,3).text <> "试卷名称" Then
MessageBox.Show("您的数据源不符合国家开放大学报表平台的数据格式,不能导入学生信息表数据!", "提示")
Else
DataTables("考试数据表").StopRedraw
For i As Integer = 3 To sheet.Rows.Count -1
xh = sheet(i,1).text
sjh = sheet(i,2).text
rq = sheet(i,6).text
sj = sheet(i,7).text
js = sheet(i,8).text
zwh = sheet(i,9).text
Dim dr As DataRow = DataTables("考试数据表").find("学号 = '" & xh & "' and 试卷号 = '" & sjh & "'")
If dr IsNot Nothing Then
dr("日期") = rq
dr("时间") = sj
dr("教室") = js
If zwh <> "" Then
dr("座位号") = CInt(zwh)
End If
End If
StatusBar.ProgressBar.Value = i
StatusBar.Message2= Math.Ceiling(i/sheet.Rows.Count * 100) & "%"
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
MessageBox.Show("祝贺你!机考数据导入成功!")
StatusBar.Reset()