Foxtable(狐表)用户栏目专家坐堂 → execl导入合并的问题


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

主题:execl导入合并的问题

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/30 16:52:00 [显示全部帖子]

Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    For Each f As String In dlg.FileNames
        Dim  Book As New XLS.Book(f)
        Dim Sheet As XLS.Sheet = Book.Sheets(0)
        Dim dic As new Dictionary(Of String, Integer)
        For i As Integer = 0 To sheet.Cols.Count - 1
            If sheet(0,i).Text <> Nothing
                dic.Add(sheet(0,i).Text,i)
            End If
        Next
        For  n As Integer = 1 To Sheet.Rows.Count -1
            Dim filter As String = "入住时间 = #" & sheet(n, dic("入住时间")).Text & "# and 姓名 = '" & sheet(n, dic("姓名")).Text & "' and 房间号 = '" & sheet(n, dic("房间号")).Text & "'"
            Dim dr As DataRow =  DataTables("表A").find(filter)
            If dr Is Nothing Then dr = DataTables("表A").AddNew
            For Each c As String In dic.Keys
                If DataTables("表A").datacols.Contains(c) Then
                    dr(c) = sheet(n, dic(c)).Text
                End If
            Next
        Next
    Next
   
End If

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/30 17:02:00 [显示全部帖子]

Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    For Each f As String In dlg.FileNames
        Dim  Book As New XLS.Book(f)
        Dim Sheet As XLS.Sheet = Book.Sheets(0)
        Dim dic As new Dictionary(Of String, Integer)
        For i As Integer = 0 To sheet.Cols.Count - 1
            If sheet(0,i).Text <> Nothing
                dic.Add(sheet(0,i).Text,i)
            End If
        Next
        For  n As Integer = 1 To Sheet.Rows.Count -1
            If sheet(n, dic("入住时间")).Text > "" Then
                Dim filter As String = "入住时间 = #" & sheet(n, dic("入住时间")).Text & "# and 姓名 = '" & sheet(n, dic("姓名")).Text & "' and 房间号 = '" & sheet(n, dic("房间号")).Text & "'"
                Dim dr As DataRow =  DataTables("表A").find(filter)
                If dr Is Nothing Then dr = DataTables("表A").AddNew
                For Each c As String In dic.Keys
                    If DataTables("表A").datacols.Contains(c) Then
                        dr(c) = sheet(n, dic(c)).Text
                    End If
                Next
            End If
        Next
    Next
   
End If

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/30 21:16:00 [显示全部帖子]

Dim dlg As new OpenFileDialog
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
    For Each f As String In dlg.FileNames
        Dim  Book As New XLS.Book(f)
        Dim Sheet As XLS.Sheet = Book.Sheets(0)
        Dim dic As new Dictionary(Of String, Integer)
        For i As Integer = 0 To sheet.Cols.Count - 1
            If sheet(0,i).Text <> Nothing
                dic.Add(sheet(0,i).Text,i)
            End If
        Next
        Dim tdic As new Dictionary(of DataRow, Integer)
        Dim tls As new List(of Integer)
        For  n As Integer = 1 To Sheet.Rows.Count -1
            If sheet(n, dic("入住时间")).Text > "" Then
                Dim filter As String = "入住时间 = #" & sheet(n, dic("入住时间")).Text & "# and 姓名 = '" & sheet(n, dic("姓名")).Text & "' and 房间号 = '" & sheet(n, dic("房间号")).Text & "'"
                Dim dr As DataRow =  DataTables("表A").find(filter)
               
                If dr Is Nothing Then
                    tls.add(n)
                Else
                    tdic.add(dr, n)
                End If
               
            End If
        Next
        For Each key As DataRow In tdic.Keys
            For Each c As String In dic.Keys
                If DataTables("表A").datacols.Contains(c) Then
                    key(c) = sheet(tdic(key), dic(c)).Text
                End If
            Next
        Next
        For Each i As Integer In tls
            Dim dr = DataTables("表A").AddNew
            For Each c As String In dic.Keys
                If DataTables("表A").datacols.Contains(c) Then
                    dr(c) = sheet(i, dic(c)).Text
                End If
            Next
        Next
    Next
   
End If

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/31 14:05:00 [显示全部帖子]

1、循环每一行,获取日期比较

 

2、DataTables("导入客户资料").DeleteFor("[入住时间] <= #" & 日期1 & "# and [入住时间] >= #" & 日期2 & "#")


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/31 14:05:00 [显示全部帖子]

要效率更快就用数据源的方式

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=52744&skin=0

 

 

下载信息  [文件大小:312.0 KB  下载次数:8]
图片点击可在新窗口打开查看点击浏览该文件:excel作为数据源_合并.table


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/31 15:26:00 [显示全部帖子]

用11楼加filler填充。

 

http://www.foxtable.com/help/topics/0680.htm

 


 回到顶部