以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求助  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=48410)

--  作者:caiankie
--  发布时间:2014/3/28 12:36:00
--  求助

我现有一段代码,已能成功地将"面积计算表"导入到"订单明细表",我是以"单号"

做为不能重复导入的条件,现有个问题麻烦各路高手帮忙解决一下,问题是我原来的“订单明细表”中有了  单号为80  的这一行,如果我要导入的“面积计算表”中也有  单号为80  的这一行,要给我个提示,且不做导入,在改正后再执行以下代码,请帮忙,谢谢

Dim Book As New XLS.Book("e:\\面积计算表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单明细表").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"单号","客户订单号","工程名称","编号","数量","长度1","长度2","长度3","长度4","宽度1","宽度2","宽度3","宽度4"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    Dim dh As String = sheet(n,0).Text
    If DataTables("订单明细表").Find("单号 = \'" & dh & "\'") 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()


--  作者:狐狸爸爸
--  发布时间:2014/3/28 13:40:00
--  

你上面的已经不会重复导入了,要提示的话:

 

Dim Book As New XLS.Book("e:\\面积计算表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)

Dim s as string
Tables("订单明细表").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"单号","客户订单号","工程名称","编号","数量","长度1","长度2","长度3","长度4","宽度1","宽度2","宽度3","宽度4"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    Dim dh As String = sheet(n,0).Text
    If DataTables("订单明细表").Find("单号 = \'" & dh & "\'") 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

     Else

          s = s & " " & dh
    End If
Next

Tables("订单明细表").ResumeRedraw()

if s > "" then

    Messagebox.show("以下单号重复,没有导入:" & s)

end if


--  作者:caiankie
--  发布时间:2014/3/28 16:35:00
--  

如果要要把数据导入子表的话能不能实现?比如说导入到“订单管理主表.订单明细表”中


--  作者:狐狸爸爸
--  发布时间:2014/3/28 16:38:00
--  

当然可以:

 

Dim Book As New XLS.Book("e:\\面积计算表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)

Dim s as string
Tables("订单明细表").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"单号","客户订单号","工程名称","编号","数量","长度1","长度2","长度3","长度4","宽度1","宽度2","宽度3","宽度4"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    Dim dh As String = sheet(n,0).Text
    If DataTables("订单明细表").Find("单号 = \'" & dh & "\'") 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

        r("订单编号") = Tables("订单").Current("订单编号")

     Else

          s = s & " " & dh
    End If
Next

Tables("订单明细表").ResumeRedraw()

if s > "" then

    Messagebox.show("以下单号重复,没有导入:" & s)

end if


--  作者:caiankie
--  发布时间:2014/3/28 17:47:00
--  
导入到“订单管理主表.订单明细表”中,不成功请 狐狸爸爸 帮忙解决,谢谢
--  作者:狐狸爸爸
--  发布时间:2014/3/28 17:49:00
--  

Dim Book As New XLS.Book("e:\\面积计算表.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)

Dim s as string
Tables("订单明细表").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"单号","客户订单号","工程名称","编号","数量","长度1","长度2","长度3","长度4","宽度1","宽度2","宽度3","宽度4"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    Dim dh As String = sheet(n,0).Text
    If DataTables("订单明细表").Find("单号 = \'" & dh & "\'") Is Nothing Then \'如果不存在同编号的订单
        Dim r As DataRow = DataTables("订单明细表").AddNew()
        For m As Integer = 0 To nms.Length - 1
            r(nms(m)) = Sheet(n,m).Value
        Next

        r("订单编号") = Tables("订单").Current("订单编号")

     Else

          s = s & " " & dh
    End If
Next

Tables("订单明细表").ResumeRedraw()

if s > "" then

    Messagebox.show("以下单号重复,没有导入:" & s)

end if


--  作者:caiankie
--  发布时间:2014/3/28 22:13:00
--  
已成功,谢谢