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
rq1 = sheet(i,6).text
sj = sheet(i,7).text
js = sheet(i,8).text
zwh = sheet(i,9).text
Dim Valuessj() As String
Dim rq2,rq3,rq4 As String
Valuessj = rq1.split("/")
rq2 = Valuessj(0)
If Valuessj(1).Length = 1 Then
rq3 = "0" & Valuessj(1)
Else
rq3 = Valuessj(1)
End If
If Valuessj(2).Length = 1 Then
rq4 = "0" & Valuessj(2)
Else
rq4 = Valuessj(2)
End If
rq = rq2 & "-" & rq3 & "-" & rq4
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()
这是我的机考导入的代码
报错是这样的
此主题相关图片如下:qq截图20150612112743.png
想解决下面日期格式不一到,
此主题相关图片如下:qq截图20150612103750.png
导致后面用目录树的情况出现下列的错误情况。
此主题相关图片如下:qq截图20150612112504.png