Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xls" '设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 Dim c As Integer = 0 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 lx As String = sheet(n,0).Text Dim zt As String = sheet(n,1).Text If DataTables("物料信息").Find("主题 = '" & zt & "' and 条目类型 = '" & lx & "'") 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
|