以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]导入时过滤掉某些行  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=86715)

--  作者:huhu
--  发布时间:2016/6/23 17:41:00
--  [求助]导入时过滤掉某些行

导入销售出库单列表.xls时,希望对仓库编码为15的不导入。怎么弄?

 

Dim App As New MSExcel.Application
try
    Dim Wb As MSExcel.Workbook = App.WorkBooks.Open("D:\\销售出库单列表.xls")
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
   
    Tables("销售出库单列表").StopRedraw()
    \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
    Dim ra = ws.UsedRange
    Dim nms() As String = {"制单人","仓库编码","仓库","销售订单号","发货单号","出库日期","出库单号","出库类别","销售部门","业务员","客户名称","备注","存货编码","存货名称","主计量单位","数量","货运单号","发货地址"}
    \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
    For n As Integer = 2 To ra.Rows.Count
        Dim fhdh As String = ws.cells(n,5).Text
        Dim chbm As String = ws.cells(n,13).text
       
        If DataTables("销售出库单列表").Find("发货单号 = \'" & fhdh & "\' and 存货编码 = \'" & chbm & "\'") Is Nothing Then \'如果不存在同编号的计划表
            Dim r As Row = Tables("销售出库单列表").AddNew()
            For m As Integer = 0 To nms.Length - 1
                r(nms(m)) = ws.cells(n,m+1).Value
            Next
        End If
    Next
    Tables("销售出库单列表").ResumeRedraw()
    Tables("销售出库单列表").save
    msgbox("导入完成")
catch ex As exception
    app.quit
End try


--  作者:大红袍
--  发布时间:2016/6/23 17:43:00
--  

For n As Integer = 2 To ra.Rows.Count

    If ws.cells(n,2).Text <> 15 Then
        Dim fhdh As String = ws.cells(n,5).Text