Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
Dim t As Table = Tables("订单原表")
t.ResumeRedraw()
t.StopRedraw()
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
Dim arg = rg.value
For n As Integer = 2 To rg.Rows.Count
Dim r As DataRow = t.DataTable.Find("商品编码 = #" & arg(n, 3) & "# and 系统单号 = '" & arg(n, 10) & "' and 商品规格 = '" & arg(n, 11) & "'")
If r Is Nothing Then r = t.DataTable.AddNew()
For i As Integer = 1 To rg.Columns.count
Dim cname As String = arg(1,i)
If cname > "" AndAlso t.Cols.Contains(cname) Then
If t.Cols(cname).IsDate AndAlso arg(n,i).Gettype.name = "double" Then
r(cname) = DateTime.FromOADate(arg(n,i))
Else
r(cname) = arg(n, i)
End If
ElseIf cname = "收件人姓名*"
r("收件人姓名") = arg(n, i)
ElseIf cname = "收件人电话/手机"
r("收件人电话") = arg(n, i)
ElseIf cname = "商品编码*"
r("商品编码") = arg(n, i)
End If
Next
Next
catch ex As exception
msgbox(ex.message)
MessageBox.Show("导入失败!","恭喜!")
finally
t.ResumeRedraw()
app.quit
End try
End If
Dim f As New Filler
f.SourceTable = DataTables("订单原表") '指定数据来源
f.SourceCols = "系统单号,原始单号,创建时间,发货时间,店铺,实付总金额,快递公司,快递单号,客户ID,收件人姓名,收件人电话,收件人地址,订单总金额,运费,留言,备注,批次流水号" '指定数据来源列
f.DataTable = DataTables("订单") '指定数据接收表
f.DataCols = "系统单号,原始单号,创建时间,发货时间,店铺,实付总金额,快递公司,快递单号,客户ID,收件人姓名,收件人电话,收件人地址,订单总金额,运费,留言,备注,批次流水号" '指定数据接收列
f.Fill() '填充数