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)
CurrentTable.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 = CurrentTable.AddNew()
For m As Integer = 0 To nms.Length - 1
If nms(m) = "长丝" OrElse nms(m) = "短纤"
r(nms(m)) = IIF(Sheet(n,m).Value = 1,True,False)
Else
r(nms(m)) = Sheet(n,m).Value
End If
Next
End If
Next
CurrentTable.ResumeRedraw()
End If