Foxtable(狐表)用户栏目专家坐堂 → [求助]符合条件导入问题


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

主题:[求助]符合条件导入问题

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/6/9 10:41:00 [显示全部帖子]

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("表A")
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim cr As Row = Nothing
        For Each r As Row In t.Rows
        Dim count As Integer = 0
            If r("主机厂") = sheet(n, 0).text Then count += 1
            If r("商品车") = sheet(n, 2).text Then count += 1
            If r("清单号") = sheet(n, 3).text Then count += 1
            If r("底盘号") = sheet(n, 4).text Then count += 1
            If count >= 3 Then
                cr = r
                Exit For
            End If
        Next
        If cr Is Nothing Then cr = Tables("表B").AddNew()
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If cr.Table.Cols.Contains(cname) Then
                cr(cname) = sheet(n, i).Text
            ElseIf cname = "对账金额" Then
                cr("实际对账金额") = sheet(n, i).Text
            End If
        Next
    Next
   
End If

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/6/9 11:25:00 [显示全部帖子]

 

你上次的excel,我用代码测试没问题。

 


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/6/9 17:08:00 [显示全部帖子]

1、excel文件发上来测试;

 

2、截图说明哪条数据符合。


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/6/10 12:32:00 [显示全部帖子]

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("表A")
    Dim n1 As Integer = 0
    Dim n2 As Integer = 0
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim cr As Row = Nothing
        For Each r As Row In t.Rows
            Dim count As Integer = 0
            If r("主机厂") = sheet(n, 0).text Then count += 1
            If r("商品车") = sheet(n, 1).text Then count += 1
            If r("清单号") = sheet(n, 2).text Then count += 1
            If r("底盘号") = sheet(n, 3).text Then count += 1
            If count >= 3 Then
                cr = r
                Exit For
            End If
        Next
        If cr Is Nothing Then
            cr = Tables("表B").AddNew()
            n1 += 1
        Else
            n2 += 1
        End If
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If cr.Table.Cols.Contains(cname) Then
                cr(cname) = sheet(n, i).Text
            ElseIf cname = "对账金额" Then
                cr("实际对账金额") = sheet(n, i).Text
            End If
        Next
    Next
    msgbox(n1 & " " & n2)
End If

 回到顶部