以文本方式查看主题

-  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=183161)

--  作者:swindy
--  发布时间:2022/10/26 15:22:00
--  [求助]Excel导入
想把上面改成以下改品名1和品名2合成第二张图的品名?是不是用“手工编码填充数据”? 

图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2022/10/26 15:26:00
--  
可以的
--  作者:swindy
--  发布时间:2022/10/26 15:55:00
--  
Dim Cols1(表A) As String = {"科室", "领料人", "工号", "申领日期", "品名1", "品名1数量", "品名2", "品名2数量"}
Dim Cols2(表B) As String = {"科室", "领料人", "工号", "申领日期", "品名1", "品名1数量", "品名2", "品名2数量"}
For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim dr2 As DataRow = DataTables("表B").AddNew()
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
Next

不行。 麻烦帮忙看一下。
[此贴子已经被作者于2022/10/26 15:56:31编辑过]

--  作者:有点蓝
--  发布时间:2022/10/26 16:00:00
--  
多看看基础:http://www.foxtable.com/webhelp/topics/1592.htm,很多基本的语法都没搞懂

Dim Cols1() As String = {"科室", "领料人", "工号", "申领日期"}
For Each dr1 As DataRow In DataTables("表A").datarowas
    Dim dr2 As DataRow = DataTables("表B").AddNew()
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
dr2("品名") = dr1("品名1")
dr2("品名数量") = dr1("品名1数量")
if dr1.isnull("品名2") = false then
    dr2 = DataTables("表B").AddNew()
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
dr2("品名") = dr1("品名2")
dr2("品名数量") = dr1("品名2数量")
endif
Next

--  作者:swindy
--  发布时间:2022/10/26 16:20:00
--  
如果我有品名1品名6的话变成品名, 还有更简单的写法吗?
--  作者:有点蓝
--  发布时间:2022/10/26 16:36:00
--  
放到循环里咯
Dim s1() As String = {"品名1", "....", "品名6"}
Dim s2() As String = {"数量1", "....", "数量6"}
for k as integer  = 0 to s1.length -1
if dr1.isnull(s1(k)) = false then
    dr2 = DataTables("表B").AddNew()
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols2(i)) = dr1(Cols1(i))
    Next
dr2("品名") = dr1(s1(k))
dr2("品名数量") = dr1(s2(k))
endif

--  作者:swindy
--  发布时间:2022/10/27 11:26:00
--  
不好意思 还是不行 

Dim s1() As String = {"品名1", "品名2", "品名3", "品名4", "品名5", "品名6"}
Dim s2() As String = {"品名1数量", "品名2数量", "品名3数量", "品名4数量", "品名5数量", "品名6数量"}
For Each dr1 As DataRow In DataTables("表A").DataRows
    For k As Integer = 0 To s1.length - 1
        If dr1.isnull(s1(k)) = False Then
            Dim dr2 As DataRow = DataTables("表B").AddNew()
            For i As Integer = 0 To s1.Length - 1
                dr2(s1(i)) = dr1(s2(i))
            Next
            dr2("品名") = dr1(s1(k))
            dr2("品名数量") = dr1(s2(k))
        End If
    Next
Next图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2022/10/27 11:35:00
--  
Dim Cols1() As String = {"科室", "领料人", "工号", "申领日期"}
Dim s1() As String = {"品名1", "品名2", "品名3", "品名4", "品名5", "品名6"}
Dim s2() As String = {"品名1数量", "品名2数量", "品名3数量", "品名4数量", "品名5数量", "品名6数量"}
For Each dr1 As DataRow In DataTables("表A").datarowas
for k as integer  = 0 to s1.length -1
if dr1.isnull(s1(k)) = false then
    dr2 = DataTables("表B").AddNew()
    For i As Integer = 0 To Cols1.Length - 1
        dr2(Cols1(i)) = dr1(Cols1(i))
    Next
dr2("品名") = dr1(s1(k))
dr2("品名数量") = dr1(s2(k))
endif
Next

--  作者:swindy
--  发布时间:2022/10/27 12:04:00
--  
谢谢 蓝大 !!