Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在SSRS中导出到Excel时,代码段未按预期执行_Vba_Reporting Services_Ssrs 2008 - Fatal编程技术网

Vba 在SSRS中导出到Excel时,代码段未按预期执行

Vba 在SSRS中导出到Excel时,代码段未按预期执行,vba,reporting-services,ssrs-2008,Vba,Reporting Services,Ssrs 2008,在我的代码中,我要做的是 ID Value 1 a 1 b 1 c 2 a 2 b 我越来越 ID Value 1 a,b,c 2 a,b 我可以在SQL中使用STUFF关键字来实现它,但我已经决定使用这个 在我写的报告的代码部分 Private CurrGroupBy As String = String.Empty Private ConcatVal As String = String.Empty Public Function Ag

在我的代码中,我要做的是

ID   Value
1    a
1    b
1    c
2    a
2    b
我越来越

ID   Value
1    a,b,c
2    a,b
我可以在SQL中使用STUFF关键字来实现它,但我已经决定使用这个

在我写的报告的代码部分

Private CurrGroupBy As String = String.Empty
Private ConcatVal As String = String.Empty

Public Function AggConcat(GroupBy as String, ElementVal as String) as String
    If CurrGroupBy = GroupBy Then
        If InStr(ConcatVal, ElementVal,0) = 0 Then
            ConcatVal = Trim(ConcatVal) & ", " & ElementVal 
        End If
    Else
        CurrGroupBy = GroupBy 
        ConcatVal = ElementVal 
    End If
Return ConcatVal 
End Function
在其中一行中,我使用下面的表达式

=RunningValue(Code.AggConcat(Fields!Id.Value, Fields!Theme.Value), Last, "DataSet1")
如果查看报告并将其导出为PDF格式,则此操作非常有效。但是,当我将其导出到Excel时,我得到的结果是

ID   Value
1    a
1    a,b
1    a,b,c
2    a
2    a,b

我做错什么了?

我不知道。如果起始代码在excel中,则可以修改此代码以执行所需操作。我很久以前就发现了这个。如果它不是你想要的,忽略它

Sub ConcatNotesTextV2()
' hiker95, 04/14/2012
' http://www.mrexcel.com/forum/showthread.php?t=628561
Dim r As Long, lr As Long, nr As Long, n As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
For r = 2 To lr
  n = Application.CountIf(Columns(1), Cells(r, 1).Value)
   If n = 1 Then
     'do nothing
  ElseIf n > 1 Then
    Range("B" & r) = Join(Application.Transpose(Range("B" & r & ":B" & (r + n) - 1)), ,)
    Range("A" & r).Offset(1).Resize(n - 1).ClearContents
  End If
  r = r + n - 1
Next r
On Error Resume Next
Range("A1:A" & Cells(Rows.Count, 2).End(xlUp).Row).SpecialCells        (xlCellTypeBlanks).EntireRow.Delete  
On Error GoTo 0
Application.ScreenUpdating = True
End Sub

当我试图重现上面解释的内容时,报表查看器和excel都生成了所描述的意外场景

虽然为了实现所需的输出,我添加了一个报告组并删除了
=(详细信息)
组,但这在报告视图和导出到Excel时都有效

解决方案最终看起来像:


您能告诉我这是SSRS 2008还是2008 R2吗?这两个版本有不同的选项。这是SSRS 2008R2+1中的
STUFF
关键字,我以前从未听说过。谢谢Matthew!我的报告中有两个tablix,一个用于excel,另一个用于其他所有内容,我完全忘记了excel tablix中的分组。非常感谢。我很高兴它帮你整理好了。