改了后可以了,但是老师我看帮助导入可以判断出重复内容的代码,我导入按钮改这个后,居然导入选中文件后没反应,一条数据都没有导入进来
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("物料信息").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"物料编号","物料名称","型号规格","单价","数量","客户","备注信息"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
Dim bh As String = sheet(n,0).Text
If DataTables("物料信息").Find("物料编号 = '" & bh & "'") Is Nothing Then '如果不存在同编号的订单
Dim r As Row = Tables("物料信息").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = Sheet(n,m).Value
Next
End If
Next
Tables("物料信息").ResumeRedraw()
End If