Dim str As String Dim tj As Integer Dim dlg As New OpenFileDialog dlg.MultiSelect = True dlg.Filter= "Excel 工作薄(*.xls)|*.xls|Excel 工作薄(*.xlsx)|*.xlsx" '设置筛选器 If dlg.ShowDialog = DialogResult.OK Then For Each fl As String In dlg.FileNames Dim Book As New XLS.Book(fl) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim Names As New List(Of String) For i As Integer = 0 To Sheet.cols.count -1 Names.Add(Sheet(0,i).value) Next If Names.Contains("统编学籍号")= False Then MessageBox.Show("导入表中不含""统编学籍号""列", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question) Return End If tj = Nothing For i As Integer = 0 To Sheet.cols.count -1 If Sheet(0,i).value = "统编学籍号" Then tj = i Exit For End If Next str = Nothing For i As Integer = 0 To Sheet.cols.count -1 If str = "" Then str = Sheet(0,i).value Else str = str & "|" & Sheet(0,i).value End If Next If str = "" Then MessageBox.Show("无匹配字段", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question) Return End If Dim Values() As String = str.split("|") e.Form.Controls("Label1").text = FileSys.GetName(fl) Application.DoEvents() For ii As Integer = 1 To Sheet.Rows.count - 1 Dim dr As DataRow = DataTables("Testlist").Find("[统编学籍号] = '" & Sheet(ii,tj).value & "'") If dr IsNot Nothing Then For i As Integer = 0 To Values.Length - 1 dr(Values(i)) = Sheet(ii,i).value Next Else Dim dr1 As DataRow = DataTables("Testlist").AddNew() For i As Integer = 0 To Values.Length - 1 dr1(Values(i)) = Sheet(ii,i).value Next End If Next Next e.Form.Controls("Label1").Text = "已经完成." MessageBox.Show("数据汇总完毕,请检查数据!", "汇总提示", MessageBoxButtons.OK, MessageBoxIcon.Question) Dim dlg1 As New SaveFileDialog '定义一个新的SaveFileDialog dlg1.Filter= "Excel文件|*.xls" '设置筛选器 If dlg1.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 Dim flg As New SaveExcelFlags flg.CellStyle = True flg.RowNumber =True CurrentTable.SaveExcel(dlg1.FileName,"Testlist",flg) End If End If
|