Dim pr As Integer = DataTables("检查").DataRows.Count '查询表行数
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = { "编号","工程","班","作业日","正常时间","加班时间","工号","姓名","机台号码","型号","辅助编码","管理号码","管理号码1","管理号码2","生产数","良品","不良品","段取品","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","开始时间","结束时间","开动时间","连班时间","稼动时间","检查","切边","自动切边","空检","磁检","套弹簧","组装","防锈包装","称油脂","返工","不良调试","毛边确认","气泡确认","裂开确认","作业标准","能力","必要时间","生产效率","故障时间","材料时间","品检时间","异常时间","段取时间","调整时间","初品时间","其它时间" }
Tables("检查").ResumeRedraw()
Tables("检查").StopRedraw()
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
For n As Integer = 3 To rg.Rows.Count
Dim bh As String = ws.Cells(n,1).Text
Dim dr As DataRow = DataTables("检查").Find("编号 = '" & bh & "'")
If dr Is Nothing Then '如果不存在同编号的订单
dr = DataTables("检查").AddNew()
End If
For m As Integer = 0 To nms.Length - 1
dr(nms(m)) = ws.Cells(n,m+1).Value
Next
Next
catch ex As exception
msgbox(ex.message)
finally
Tables("检查").ResumeRedraw()
app.quit
End try
Tables("检查").ResumeRedraw()
pr = DataTables("检查").DataRows.Count - pr '查询表行数
MessageBox.Show("成功导入数据"& pr &"条","提示")
End If
Syscmd.Table.ToggleSortAndFilter()
DataTables("检查").Save()