Dim pr As Integer = DataTables("加硫").DataRows.Count '查询表行数
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "excel文件|*.xls" '设置筛选器
dlg.MultiSelect = True '允许选择多个文件
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim mg As New Merger
For Each fl As String In dlg.FileNames
mg.SourcePath = fl '指定数据文件
mg.Format = "excel" '指定格式
mg.SourceTableName = "data$" '指定要合并的表
mg.DataTableName = "加硫" '指定接收数据的表
mg.Merge() '开始合并
Next
Dim str As String = "管理号码,管理号码1,工号,生产数"
Dim idx As String = ""
Dim ary() As String = str.Split(",")
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
For Each dr As DataRow In DataTables("加硫").Select("管理号码 is not null", str)
Dim flag As Boolean = False
For Each a As String In ary
If pdr IsNot Nothing AndAlso dr(a) <> pdr(a) Then
flag = True
End If
Next
If flag = False Then
count += 1
Else
'If count = 1 Then
idx &= pdr("_Identify") & ","
'End If
count = 1
End If
pdr = dr
Next
For Each a As String In ary
If pdr IsNot Nothing AndAlso Tables("加硫").Rows(Tables("加硫").Rows.count-2)(a) <> pdr(a) Then
idx &= pdr("_Identify") & ","
End If
Next
DataTables("加硫").DeleteFor("_Identify not in (" & idx.trim(",") & ")") '去重复值
'DataTables("加硫").DeleteFor("[管理号码] is null or [良品] is null") '删除空白行
pr = DataTables("加硫").DataRows.Count - pr '查询表行数
MessageBox.Show("成功导入数据"& pr &"条","提示")
Syscmd.Table.ToggleSortAndFilter()
DataTables("加硫").Save()
End If