以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]导入Excel 文件如何过滤重复的行【已解决】  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=101056)

--  作者:静听枫雨
--  发布时间:2017/5/24 11:45:00
--  [求助]导入Excel 文件如何过滤重复的行【已解决】

我用下面的代码,只能导入,不能过滤掉重复的客户

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    For Each fl As String In dlg.FileNames
        Dim mg As New Merger
        mg.SourcePath = fl
        mg.Format = "Excel"  \'指定要导入的格式
        mg.SourceTableName = "Sheet1$" \'指定要合并的表
        mg.DataTableName = "客户表" \'指定接收数据的表
        mg.Merge()
    Next
DataTables("客户表").Save()
End If

 

找客服说,用合并数据

 

Dim Book As New XLS.Book("c:\\test\\订单.xls")
Dim
Sheet As XLS.Sheet = Book.Sheets(0)
Tables(
"订单").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致

Dim
nms() As String = {"编号","产品","客户","雇员","单价","折扣","数量","日期"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题

For
n As Integer = 1 To Sheet.Rows.Count -1
   
Dim bh As String = sheet(n,0).Text
   
If DataTables("订单").Find("编号 = \'" & bh & "\'") Is Nothing Then \'如果不存在同编号的订单
        Dim
r As Row = Tables("订单").AddNew()
        For
m As Integer = 0 To nms.Length - 1
           
r(nms(m)) = Sheet(n,m).Value
       
Next
    End If
Next
Tables(
"订单").ResumeRedraw()

 

是不是要把 两个代码放在一起用。如何使用,不会搞了,望老师指导

 

[此贴子已经被作者于2017/5/24 13:01:00编辑过]

--  作者:有点色
--  发布时间:2017/5/24 12:14:00
--  

mark 合并数据

 

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("表B")
    t.StopRedraw()
    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 r As DataRow = t.DataTable.Find("第一列 = \'" & sheet(n, 0).text & "\'")
        If r Is Nothing Then r = t.DataTable.AddNew()
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If t.Cols.Contains(cname) Then
                r(cname) = sheet(n, i).Text
            End If
        Next
    Next
    t.ResumeRedraw()
End If


--  作者:静听枫雨
--  发布时间:2017/5/24 12:23:00
--  
谢谢版主,如何加个提示。导入多少条信息呢
--  作者:有点色
--  发布时间:2017/5/24 12:28:00
--  
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("表B")
    t.StopRedraw()
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Dim newcount As Integer = 0
    Dim oldcount As Integer = 0
    For n As Integer = 1 To Sheet.Rows.Count -1
        Dim r As DataRow = t.DataTable.Find("第一列 = \'" & sheet(n, 0).text & "\'")
        If r Is Nothing Then
            r = t.DataTable.AddNew()
            newcount += 1
        Else
            oldcount += 1
        End If
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If t.Cols.Contains(cname) Then
                r(cname) = sheet(n, i).Text
            End If
        Next
    Next
    msgbox("新增" & newcount & "    " & "更新旧数据" & oldcount)
    t.ResumeRedraw()
End If

--  作者:静听枫雨
--  发布时间:2017/5/24 12:46:00
--  
谢谢版主老师。已解决!!!
[此贴子已经被作者于2017/5/24 13:00:37编辑过]

--  作者:hrlong
--  发布时间:2018/2/12 20:55:00
--  
mark 一下
--  作者:lhm11111
--  发布时间:2018/10/4 17:52:00
--  
有没有一个方法让外部实时更新的Excel文件同步到狐表里面来
--  作者:有点甜
--  发布时间:2018/10/4 18:13:00
--  
下载信息  [文件大小:312.0 KB  下载次数:4]
图片点击可在新窗口打开查看点击浏览该文件:excel作为数据源_合并.table

--  作者:18504175995
--  发布时间:2019/1/16 19:12:00
--  
请问这段代码要在哪里写入才能发送EXCEL导入指令?

 

Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    Dim t As Table = Tables("表B")
    t.StopRedraw()
    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 r As DataRow = t.DataTable.Find("第一列 = \'" & sheet(n, 0).text & "\'")
        If r Is Nothing Then r = t.DataTable.AddNew()
        For i As Integer = 0 To sheet.Cols.Count -1
            Dim cname As String = sheet(0, i).text
            If t.Cols.Contains(cname) Then
                r(cname) = sheet(n, i).Text
            End If
        Next
    Next
    t.ResumeRedraw()
End If


--  作者:有点甜
--  发布时间:2019/1/16 20:08:00
--  

命令窗口,或者做一个按钮

 

http://www.foxtable.com/webhelp/scr/1840.htm