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 ls As Integer = 0 To Sheet.Cols.count -1 '把目标表中的列名变成集合 Names.Add(Sheet(0,ls).value) Next If Names.Contains("统编学籍号")= False Then MessageBox.Show(FileSys.GetName(fl) & "表:" & vbcrlf & "不含""统编学号""字段列", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question) Return Else e.Form.Controls("Label1").text = FileSys.GetName(fl) Application.DoEvents() For i As Integer = 1 To Sheet.Rows.count - 1 Dim dr As DataRow = DataTables("Testlist").Find("[统编学籍号] = '" & Sheet(i,3).Value & "'") If dr IsNot Nothing Then '如果当前表找到此列 For ii As Integer = 0 To Sheet.cols.count - 1 dr(Sheet(0,ii).value) = sheet(i,ii).Value Next Else Dim dr1 As Row = Tables("Testlist").AddNew() '无此列就增加行并复制数据 For ii As Integer = 0 To Sheet.cols.count - 1 dr1(Sheet(0,ii).value) = sheet(i,ii).Value Next End If Next End If 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
|