Dim dlg As new OpenFileDialog dlg.Filter = "excel文件|*.xls;*.xlsx" 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(1) Tables("商机单跟进表").StopRedraw() Dim nms() As String = {"受理时间","外呼时间","录入时间"} Dim dict As new Dictionary(of String,Integer) Dim dict2 As new Dictionary(of String,Integer) Dim Rg As MSExcel.Range = Ws.UsedRange Dim ary = rg.value For c As Integer = 1 To rg.Columns.Count If array.Indexof(nms, ary(1, c)) >= 0 Then dict.add(ary(1, c), c) End If If Tables("商机单跟进表").Cols.Contains(ary(1,c)) Then dict2.add(ary(1, c), c) End If Next Dim newcount As Integer = 0 Dim Modifycount As Integer = 0 For n As Integer = 2 To rg.Rows.count Dim bh As String = ary(n, 4) Dim dr As DataRow = DataTables("商机单跟进表").Find("工单号或受理人 = '" & bh & "'") If dr Is Nothing Then '如果不存在同编号的订单 dr = DataTables("商机单跟进表").AddNew() For Each key As String In dict2.Keys dr(key) = ary(n,dict2(key)) Next newcount += 1 Else For Each key As String In dict.Keys dr(key) = ary(n,dict(key)) Next Modifycount += 1 End If Next Tables("商机单跟进表").ResumeRedraw() msgbox(newcount & " " & Modifycount) catch ex As exception msgbox(ex.message) app.quit End try End If
|