Foxtable(狐表)用户栏目专家坐堂 → excel数据更新到项目的问题


  共有4440人关注过本帖树形打印复制链接

主题:excel数据更新到项目的问题

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/14 17:49:00 [显示全部帖子]

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

 回到顶部