dlg.Filter= "Excel2003文件|*.xls|Excel2007文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim App As New MSExcel.Application
Dim Book As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
'Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim Sheet As MSExcel.WorkSheet = Book.WorkSheets(1)
Dim Rg As MSExcel.Range = Sheet.UsedRange
Tables("APS排产导入").StopRedraw()
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"目的地","订单编号","产品说明","资源名称","数量","已排程的开始日期","已排程结束日期"}
'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
Dim k() As Integer = {2,3,4,5,6,8,9}
Dim w As Integer
Dim f As String
Dim q As Date
Dim q1 As Date
w =dlg.FileName.LastIndexOf("\")
f = dlg.FileName.SubString(w+1)
q = f.SubString(7,9)
'For n As Integer = 2 To Sheet.Rows.Count -1
For n As Integer = 2 To rg.Rows.Count
q1 = Sheet.Cells(n,8).Text.SubString(0,9)
If q1 = q Then
Dim r As Row = Tables("APS排产导入").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = Sheet.Cells(n,k(m)).Value
r("导入文件名") = f
r("文件名日期") = q
Next
End If
Next
Tables("APS排产导入").ResumeRedraw()
MessageBox.Show("导入完成!")
Tables("APS排产导入").DataTable.Save
End If