Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件(xls,xlsx)|*.xls;*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮Dim Book As New XLS.Book("c:\test\订单.xls")
Dim count As Integer =0
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("到货表").StopRedraw()
e.Form.Controls("Panel2").Visible=True
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = Sheet.Rows.Count '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
Dim hh As Integer
Dim xl As Integer
For i As Integer = 0 To Sheet.Cols.Count -1 ' 用来判断导入文件的表头
If sheet(1,i).Text.Trim() = "存货编码"
hh = i
Else If sheet(1,i).Text.Trim() = "数量"
xl = i
End If
Next
Dim drs2 As List(Of DataRow) = DataTables("到货表").Select("")
For Each dr1 As DataRow In drs2
dr1("最近30天销量")= 0
Next
'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
'*:商品类型*:类型*:品牌*:商品编码*:货号*:货品名称*:商品规格*:销售单价*:销售量*:销售额*:日均销售额*:日均销售量*:退货量*:退货率*:退货总额*:平均成本*:销售成本*:销售平均毛利*:销售毛利*:销售毛利率
For n As Integer = 2 To Sheet.Rows.Count -1 '注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
p.Value=p.Value+1
Dim bh As String = sheet(n,hh).Text.Trim()
Dim dr As DataRow
dr = DataTables("到货表").Find("[货号] = '" & bh & "'")
If dr IsNot Nothing Then '如果不存在同编号的订单
Dim drs1 As List(Of DataRow) = dr.GetChildRows("基本表")
For Each dr1 As DataRow In drs1
If dr1("级别") <> "PJ" Then
dr("最近30天销量")=Sheet(n,xl).Value
count=count+1
End If
Next
End If
Next
Tables("到货表").ResumeRedraw()
e.Form.Controls("Panel2").Visible=False
MessageBox.Show("导入成功! 共导入" & count & "条记录.")
Dim drs As List(Of DataRow)
DataTables("到货表").Save()
drs = DataTables("导入记录").Select("[导入数据表名] = '30天销量表'")
For Each dr As DataRow In drs
dr("导入时间") = Date. Now
Next
DataTables("导入记录").Save()
End If