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, 1) & "' and 商品编码 = '" & arg(n, 24) & "'")
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 t2 As Table = Tables("订单简表")
t2.ResumeRedraw()
t2.StopRedraw()
Dim App2 As New MSExcel.Application
try
Dim Wb2 As MSExcel.WorkBook = App2.WorkBooks.Open(dlg.FileName)
Dim Ws2 As MSExcel.WorkSheet = Wb2.WorkSheets(1)
Dim Rg2 As MSExcel.Range = Ws2.UsedRange
Dim arg2 = rg2.value
For n As Integer = 2 To rg2.Rows.Count
Dim r2 As DataRow = t2.DataTable.Find("系统单号 = '" & arg2(n, 1) & "'")
If r2 Is Nothing Then r2 = t2.DataTable.AddNew()
For i As Integer = 1 To rg2.Columns.count
Dim cname As String = arg2(1,i)
If cname > "" AndAlso t2.Cols.Contains(cname) Then
If t2.Cols(cname).IsDate AndAlso arg2(n,i).Gettype.name = "double" Then
r2(cname) = DateTime.FromOADate(arg2(n,i))
Else
r2(cname) = arg2(n, i)
End If
ElseIf cname = "收件人姓名*"
r2("收件人姓名") = arg2(n, i)
ElseIf cname = "收件人电话/手机"
r2("收件人电话") = arg2(n, i)
End If
Next
Next
catch ex As exception
msgbox(ex.message)
MessageBox.Show("导入失败!","恭喜!")
finally
t2.ResumeRedraw()
app2.quit
End try