Foxtable(狐表)用户栏目专家坐堂 → 如何将表一汇总到表二里面


  共有2501人关注过本帖树形打印复制链接

主题:如何将表一汇总到表二里面

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/14 16:21:00 [显示全部帖子]

1、具体的项目发上来测试;

 

2、你的问题是如何拆分一段字符串,如【土建120平方,安装12万元】,拆分各个项目和资金?


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/11/14 17:40:00 [显示全部帖子]

1、先拆分各个项目,参考代码

 

Dim str As String = "土建100平方米50万元,装修50平方米30万元,安装80万元"
Dim mc = System.Text.RegularExpressions.Regex.Matches(str, "(?<=土建|土建[0-9]+平方米)[0-9]+(?=万元)")
If mc.count > 0 Then
    msgbox(mc(0).value)
End If
mc = System.Text.RegularExpressions.Regex.Matches(str, "(?<=装修|装修[0-9]+平方米)[0-9]+(?=万元)")
If mc.count > 0 Then
    msgbox(mc(0).value)
End If
mc = System.Text.RegularExpressions.Regex.Matches(str, "(?<=安装|安装[0-9]+平方米)[0-9]+(?=万元)")
If mc.count > 0 Then
    msgbox(mc(0).value)
End If

 

 


2、写成动态的方式,如

 

'''
Dim str As String = "土建100平方米50万元,装修50平方米30万元,安装80万元"
For Each s As String In str.split(",")
    Dim mc = System.Text.RegularExpressions.Regex.Matches(s, ".+?(?=[0-9]+)")
    If mc.count > 0 Then
        Dim xm = mc(0).value
        msgbox(xm)
        mc = System.Text.RegularExpressions.Regex.Matches(str, "(?<=" & xm & "|" & xm & "[0-9]+平方米)[0-9]+(?=万元)")
        If mc.count > 0 Then
            msgbox(mc(0).value)
        End If
    End If
Next

 

 


3、动态生成表,统计数据

 

'''
Dim dic2 As new Dictionary(of String, object)
Dim xms As new List(of String)
For Each dr As DataRow In DataTables("表A").Select("年份 is not null")
    Dim str As String = dr("项目规模")
    Dim year As String = cdate(dr("年份")).year
    If dic2.ContainsKey(year) = False Then
        Dim dic As new Dictionary(of String, Double)
        dic2.Add(year, dic)
    End If
    Dim dic1 As Dictionary(of String, Double) = dic2(year)
    For Each s As String In str.split(",")
        Dim mc = System.Text.RegularExpressions.Regex.Matches(s, ".+?(?=[0-9]+)")
        If mc.count > 0 Then
            Dim xm = mc(0).value
            If xms.Contains(xm) = False Then
                xms.add(xm)
            End If
            mc = System.Text.RegularExpressions.Regex.Matches(str, "(?<=" & xm & "|" & xm & "[0-9]+平方米)[0-9]+(?=万元)")
            If mc.count > 0 Then
                If dic1.ContainsKey(xm) = False Then
                    dic1.Add(xm,mc(0).value)
                Else
                    dic1(xm) += mc(0).value
                End If
            End If
        End If
    Next
Next
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("年份", Gettype(String), 32)
For Each xm As String In xms
    dtb.AddDef(xm, Gettype(Double))
Next
dtb.Build()
Dim t As Table = Tables("统计")
For Each key As object In dic2.Keys
    Dim nr As Row = t.addnew
    nr("年份") = key
    For Each xm As String In xms
        nr(xm) = dic2(key)(xm)
    Next
Next
MainTable=t

 

[此贴子已经被作者于2018/11/14 17:40:30编辑过]

 回到顶部