Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xls|Word文件|*.doc|Access文件|*.mdb" '设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 Dim nms() As String = {"登记日期","名称","规格型号","厂家","单位","数量","金额"} Dim nms2() As String = {"日期","组件名称","规格","生产企业","单位","数量","结算金额"} Dim dict As new Dictionary(of String,String) For m As Integer = 0 To nms.Length - 1 dict.add(nms2(m),nms(m)) Next Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("表A").StopRedraw() '注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count -1 If Sheet(n,0).text > "" Then Dim r As Row = Tables("表A").AddNew() For m1 As Integer = 0 To Sheet.Cols.Count - 1 If dict.ContainsKey(Sheet(0,m1).Value) r(dict(Sheet(0,m1).Value)) = Sheet(n,m1).Value End If Next End If Next Tables("表A").ResumeRedraw() End If
|