You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSRS Lookupset结果拆分:将关联项拆分为单独行并对齐价格

解决方案:拆分Lookupset结果为独立行并对齐价格

核心思路

通过SSRS自定义代码处理Lookupset返回的数组,再用嵌套Tablix/List控件将每个关联项渲染为单独行,实现与对应价格的精准对齐。

方法1:拆分单一关联项字段(仅需显示关联项)

  1. 添加自定义代码
    打开报表属性 → 代码标签,粘贴以下VB代码:

    Function SplitLookupSet(ByVal items As Object(), ByVal delimiter As String) As String()
        If items Is Nothing OrElse items.Length = 0 Then
            Return New String() {}
        End If
        Dim result As New System.Collections.Generic.List(Of String)()
        For Each item As Object In items
            If item IsNot Nothing Then
                result.Add(item.ToString())
            End If
        Next
        Return result.ToArray()
    End Function
    
  2. 插入嵌套Tablix
    在主Tablix需要显示关联项的单元格中,插入一个嵌套Tablix(或List控件)。

  3. 配置嵌套Tablix数据源
    设置嵌套Tablix的数据源为表达式(替换实际字段和数据集名称):

    =Code.SplitLookupSet(Lookupset(Fields!主合同ID.Value, Fields!关联合同ID.Value, Fields!关联项名称.Value, "关联数据集名称"), ",")
    
  4. 绑定字段到嵌套Tablix
    在嵌套Tablix的详细行文本框中,绑定表达式:=Fields!Value.Value,此时每个关联项会自动生成单独一行。


方法2:关联项与价格一一对应(需同步显示项和价格)

如果需要关联项和对应价格严格对齐,需先组合字段再拆分:

  1. 添加自定义代码
    报表属性→代码标签,粘贴以下代码:

    Function SplitLookupPairs(ByVal items As Object(), ByVal pairDelimiter As String) As System.Collections.Generic.List(Of System.Collections.Generic.Dictionary(Of String, String))
        Dim result As New System.Collections.Generic.List(Of System.Collections.Generic.Dictionary(Of String, String))()
        If items Is Nothing OrElse items.Length = 0 Then
            Return result
        End If
        For Each item As Object In items
            If item IsNot Nothing Then
                Dim parts As String() = item.ToString().Split(pairDelimiter)
                If parts.Length = 2 Then
                    Dim dict As New System.Collections.Generic.Dictionary(Of String, String)()
                    dict.Add("Item", parts(0))
                    dict.Add("Price", parts(1))
                    result.Add(dict)
                End If
            End If
        Next
        Return result
    End Function
    
  2. 配置嵌套Tablix数据源
    用|(可替换为其他无冲突字符)组合关联项和价格,再传入自定义函数:

    =Code.SplitLookupPairs(Lookupset(Fields!主合同ID.Value, Fields!关联合同ID.Value, Fields!关联项名称.Value & "|" & Fields!关联项价格.Value, "关联数据集名称"), "|")
    
  3. 绑定对应字段
    在嵌套Tablix中添加两个文本框,分别绑定:

    • 关联项:=Fields!Item.Value
    • 价格:=Fields!Price.Value

注意事项

  • 确保主数据集与关联数据集的关联键(如合同ID)匹配正确;
  • 主Tablix的行需设置为允许增长,避免嵌套内容被截断;
  • 若使用特殊字符作为分隔符,需确保关联项/价格字段中不包含该字符,避免拆分错误。

内容的提问来源于stack exchange,提问作者SUCRAM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 21:27:40