以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]关于临时表中动态列之列宽的设置  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=141134)

--  作者:bashanren
--  发布时间:2019/9/21 23:20:00
--  [求助]关于临时表中动态列之列宽的设置

各位老师深夜辛苦!

以下代码是垂直列与水平列转换后生成的临时表,在代码最后关于列宽设置中,代码dtb.AddDef(v, Gettype(String),4,"",v & "月")所生成的列,不知列宽应该如何设置,请大师指导,谢谢各位!!


 

Dim dtb As New DataTableBuilder("DMSZNDTJB","断面水质年度统计表")
dtb.AddDef("YEAR",Gettype(String),4,"","年份")
dtb.AddDef("HLMC",Gettype(String),10,"","河流名称")
dtb.AddDef("DMMC",Gettype(String),10,"","断面名称")
For Each v As String In DataTables("DMSZJCB").GetValues("MONTH")
    dtb.AddDef(v, Gettype(String),4,"",v & "月")
Next
dtb.Build()
For Each v As String() In DataTables("DMSZJCB").GetValues("YEAR|HLMC|DMMC")
    Dim dr1 As DataRow = DataTables("DMSZNDTJB").AddNew()
    dr1("YEAR") = v(0)
    dr1("HLMC") = v(1)
    dr1("DMMC") = v(2)
    For Each dr2 As DataRow In DataTables ("DMSZJCB").Select("YEAR = \'" & v(0) & "\' And HLMC = \'" & v(1) & "\' And DMMC = \'" & v(2) & "\'")
        dr1(dr2("MONTH")) = dr2("ZHPJLB")
    Next
Next
\'DataTables("表B").DataCols.Add("总分",Gettype(Double),"[语文] + [英语] + [数学] + [物理] + [化学]")
MainTable = Tables("DMSZNDTJB")
Tables("DMSZNDTJB").SetColVisibleWidth("YEAR|40|HLMC|70|DMMC|80.................")


--  作者:狐狸爸爸
--  发布时间:2019/9/22 10:27:00
--  
For Each v As String In DataTables("DMSZJCB").GetValues("MONTH")
    dtb.AddDef(v, Gettype(String),4,"",v & "月")
Next

改为:
Dim settings as string 
For Each v As String In DataTables("DMSZJCB").GetValues("MONTH")
    dtb.AddDef(v, Gettype(String),4,"",v & "月")
    Settings = "|" & Settings & v & "|" & 120 
Next


最后:

Tables("DMSZNDTJB").SetColVisibleWidth("YEAR|40|HLMC|70|DMMC|80" & Settings )

--  作者:bashanren
--  发布时间:2019/9/22 11:13:00
--  

非常感谢“狐狸爸爸”亲自指导!

     我按照上面指导内容修改如下,但代码 dtb.AddDef(v, Gettype(String),4,"",v & "月")
    Settings = "|" & Settings & v & "|" & 3
所控制的月,本来表中有1~12月,但最终显示出来的却只有1月的,还请各位老师指导!

Dim dtb As New DataTableBuilder("DMSZNDTJB","断面水质年度统计表")
dtb.AddDef("YEAR",Gettype(String),4,"","年份")
dtb.AddDef("HLMC",Gettype(String),10,"","河流名称")
dtb.AddDef("DMMC",Gettype(String),10,"","断面名称")

Dim settings As String
For Each v As String In DataTables("DMSZJCB").GetValues("MONTH")
    dtb.AddDef(v, Gettype(String),4,"",v & "月")
    Settings = "|" & Settings & v & "|" & 3
Next

dtb.Build()
For Each v As String() In DataTables("DMSZJCB").GetValues("YEAR|HLMC|DMMC")
    Dim dr1 As DataRow = DataTables("DMSZNDTJB").AddNew()
    dr1("YEAR") = v(0)
    dr1("HLMC") = v(1)
    dr1("DMMC") = v(2)
    For Each dr2 As DataRow In DataTables ("DMSZJCB").Select("YEAR = \'" & v(0) & "\' And HLMC = \'" & v(1) & "\' And DMMC = \'" & v(2) & "\'")
        dr1(dr2("MONTH")) = dr2("ZHPJLB")
    Next
Next
MainTable = Tables("DMSZNDTJB")
Tables("DMSZNDTJB").SetColVisibleWidth("YEAR|40|HLMC|70|DMMC|80" & Settings)


--  作者:狐狸爸爸
--  发布时间:2019/9/22 11:29:00
--  
有些笔误,只是提供了一个思路。

下面的代码结果测试,通过:

Dim dtb As New DataTableBuilder("DMSZNDTJB","断面水质年度统计表")
dtb.AddDef("YEAR",Gettype(String),4,"","年份")
dtb.AddDef("HLMC",Gettype(String),10,"","河流名称")
dtb.AddDef("DMMC",Gettype(String),10,"","断面名称")

Dim settings As String
For Each v As String In DataTables("表A").GetValues("第一列")
    dtb.AddDef(v , Gettype(String),4,"",v & "月")
    Settings = Settings  &  "|" & v  & "|" & "100"
Next

dtb.Build()
MainTable = Tables("DMSZNDTJB")
Tables("DMSZNDTJB").SetColVisibleWidth("YEAR|40|HLMC|70|DMMC|80" & Settings)


--  作者:bashanren
--  发布时间:2019/9/22 14:39:00
--  
非常荣兴,谢谢“狐狸爸爸”!  问题解决!!
--  作者:bashanren
--  发布时间:2019/9/22 22:03:00
--  

“狐狸爸爸”,辛苦!各位老师辛苦!!!

 

以上的问题是解决了,可是,9月后的各列(10月、11月、12月)不是跟在9月后,页是跑到2月前和1月放在一块了,请问怎么可以才能按1——12月的顺序排列各列?


--  作者:有点蓝
--  发布时间:2019/9/22 22:22:00
--  
补全位数,按01,02,03这样设置月份,而不是1,2,3