Dim Result As DialogResult Result = MessageBox.Show("确定要导入吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If Result = DialogResult.Yes Then Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls" dlg.MultiSelect = True '允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("理论考试表").ResumeRedraw() Tables("理论考试表").StopRedraw() systemready = False Dim nms() As String = {"工作单位","县公司","姓名","性别","身份证号码","文化程度","鉴定等级","申报鉴定工种","鉴定批次","申报性质"} Dim dic As new Dictionary(Of DataRow, Integer) Dim ls As new List(Of Integer) For n As Integer = 1 To Sheet.Rows.Count -1 Dim sfzhm As String = sheet(n,4).Text Dim jdpc As String = sheet(n,8).Text Dim dr As DataRow = DataTables("理论考试表").Find("身份证号码 = '" & sfzhm & "' And 鉴定批次 = '" & jdpc & "'") If dr Is Nothing Then ls.add(n) Else dic.Add(dr, n) End If Next For Each key As DataRow In dic.Keys For m As Integer = 0 To nms.Length - 1 If DataTables("理论考试表").DataCols(nms(m)).IsBoolean Then If Sheet(dic(key),m).Value = 0 Then key(nms(m)) = False Else key(nms(m)) = True End If Else If DataTables("理论考试表").DataCols(nms(m)).Expression > "" Then '表达式列 Else If DataTables("理论考试表").DataCols(nms(m)).IsNumeric Then key(nms(m)) = val(Sheet(dic(key),m).Value) Else key(nms(m)) = Sheet(dic(key),m).Value End If Next Next For Each l As Integer In ls Dim ndr As DataRow = DataTables("理论考试表").AddNew For m As Integer = 0 To nms.Length - 1 If DataTables("理论考试表").DataCols(nms(m)).IsBoolean Then If Sheet(l,m).Value = 0 Then ndr (nms(m)) = False Else ndr (nms(m)) = True End If Else If DataTables("理论考试表").DataCols(nms(m)).Expression > "" Then '表达式列 Else If DataTables("理论考试表").DataCols(nms(m)).IsNumeric Then ndr (nms(m)) = val(Sheet(l,m).Value) Else ndr (nms(m)) = Sheet(l,m).Value End If Next Next Tables("理论考试表").ResumeRedraw() systemready = True End If End If
|