Foxtable(狐表)用户栏目专家坐堂 → 批量合并execl数据


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

主题:批量合并execl数据

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


加好友 发短信
等级:二尾狐 帖子:573 积分:2961 威望:0 精华:0 注册:2016/10/27 14:33:00
  发帖心情 Post By:2016/11/2 18:00:00 [显示全部帖子]

Dim dlg As New OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    Dim lst As new List(of String)
    lst.Add("_Identify")
    lst.Add("_Locked")
    lst.Add("_SortKey")
    lst.Add("时间")
    Dim dict As new Dictionary(of String,String)
    Dim dict2 As new Dictionary(of String,DataRow)
    For Each dt As DataTable In DataTables
        If dt.Name.StartsWith("数据") Then
            For Each c As DataCol In dt.DataCols
                If lst.Contains(c.Name) = False AndAlso dict.ContainsKey(c.Name) = False Then
                    dict.Add(c.Name,dt.Name)
                End If
            Next
            For Each r As DataRow In dt.Select("")
                If dict2.ContainsKey(dt.name & "|" & r("时间")) = False Then
                    dict2.add(dt.name & "|" & r("时间"), r)
                End If
            Next
        End If
    Next
    SystemReady = False
    For Each fl As String In dlg.FileNames
        Dim Book As New XLS.Book(fl)
        Dim Sheet As XLS.Sheet = Book.Sheets(0)
       
        For m As Integer = 1 To Sheet.Cols.Count -1
            If dict.ContainsKey(Sheet(0,m).Value) Then
                For n As Integer = 1 To Sheet.Rows.Count -1
                    Dim dr As DataRow
                    Dim cl As String  = dict(Sheet(0,m).Value) & "|" & Sheet(n,0).Value
                    If dict2.ContainsKey(cl) Then
                        dr = dict2(cl)
                    Else
                        dr = DataTables(dict(Sheet(0,m).Value)).AddNew()
                        dr("时间") =  Sheet(n,0).Value
                        dict2.Add(cl,dr)
                    End If
                    dr(Sheet(0,m).Value) = Sheet(n,m).Value
                    dict2(cl) = dr
                Next
            End If
        Next
    Next
    SystemReady = True
End If

 


 回到顶部