红版 为了不重复导入 引用你以前帮我写的代码 我把导入改为:
Dim dlg As new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
Dim App As New MSExcel.Application
try
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets("计划表")
Dim Rg As MSExcel.Range = Ws.UsedRange
Dim ary = rg.value
Tables("配载订单").ResumeRedraw()
Tables("配载订单").StopRedraw()
Dim nms() As String = {"项目","下单日期","MK号","DO号","城市","客户","送货地址","物料代码","数量","体积","重量","承运商","司机","车牌","车数","车型","出车日期"}
Dim count As Integer = 0
Dim ls As new List(of Row)
Dim dic As new Dictionary (Of DataRow, Row)
For Each r As Row In Tables("计划表").Rows
Dim filter As String = "1=1"
For Each dc As String In nms
If r.IsNull(dc) Then
filter &= " and " & dc & " is null"
Else
Dim c As Col = Tables("配载订单").Cols(dc)
If c.IsNumeric Then
filter &= " and " & dc & " = " & r(dc)
ElseIf c.IsBoolean Then
If r(dc) = True Then
filter &= " and " & dc & " = true"
Else
filter &= " and " & dc & " = false"
End If
ElseIf c.IsDate Then
filter &= " and " & dc & " = #" & r(dc) & "#"
Else
filter &= " and " & dc & " = '" & r(dc) & "'"
End If
End If
Next
Dim dr As DataRow = DataTables("配载订单").find(filter)
If dr Is Nothing Then
ls.Add(r)
count += 1
Else
dic.add(dr, r)
End If
Next
For n As Integer = 2 To ws.UsedRange.Rows.Count -1
Dim r As Row = Tables("配载订单").AddNew()
For m As Integer = 0 To nms.Length - 1
If Tables("配载订单").Cols(nms(m)).IsDate Then
Dim d As Date
If Date.TryParse(ary(n,m+1), d)
r(nms(m)) = d
End If
Else
r(nms(m)) = ary(n,m+1)
End If
Next
Next
Tables("配载订单").ResumeRedraw()
msgbox("共有 "& count &" 条数据导入" )
catch ex As exception
msgbox(ex.message)
app.quit
End try
End If
Tables("配载订单").save
e.Form.Controls("提示").Text = "正在导入,请稍后..."
Application.DoEvents()
e.Form.Controls("提示").Text = "已经导入完成."
e.Form.TimerInterval = 5000
e.Form.TimerEnabled = True
点导入时 提示没有名为"计划表"的table 计划表是外部表 要怎样写才能访问到它 另外我不知道我这样套用代码是否可行