我在获取备用行颜色时遇到一些问题。
我尝试了不同的表达方式,这已经是我已经完成的最接近的了:
=IIF(RunningValue(Fields!agent_name.Value,CountDistinct, Nothing) MOD 2 = 1, "Gainsboro", "White")
我的所有其他报告都获得了正确的替代行阴影,但我在处理这个具有行组和列组的特定报告时遇到了麻烦。花了大约 2 天,但仍然没有运气:(
My Row 组显然就是这个名字,
列组是月/年。
如有任何建议/帮助,我们将不胜感激
问题在于,矩阵在没有数据的情况下创建单元格时,数据中存在 NULL。由于这些单元格没有关联的 Agent_Name,因此它们默认为白色。
我放弃了在 SSRS 中使用运行值和行号,而通常使用交替行颜色功能。
您向报告中添加一些 VB 代码(报告属性 > 代码):
Private bOddRow(10) As Boolean
Function AlternateColor(ByVal OddColor As String, ByVal EvenColor As String, ByVal Toggle As Boolean, ByVal Type AS INTEGER) As String
If Toggle Then bOddRow(Type) = Not bOddRow(Type)
If bOddRow(Type) Then
Return OddColor
Else
Return EvenColor
End If
End Function
然后使用表达式来填充颜色:
=code.AlternateColor("AliceBlue", "White", 0, 1)
前两个参数是要交替的颜色,第三个参数是告诉它切换颜色的控件,第四个参数是用于嵌套分组的组。
该行的第一列具有第一个 1 的控件。
=code.AlternateColor("AliceBlue", "White", 1, 1)
在您的第一列中使用此 - 您的代理名称。
死灵术。
接受的答案对我不起作用,因为切换在列分组中非常不规则。
但是,下面的代码有效。
您需要将第一个单元格中的背景颜色设置为
=iif(Code.IncrementRunningValue() Mod 2 = 0, "WhiteSmoke", "White")
在所有后续单元格中
=iif(Code.GetRunningValue() Mod 2 = 0, "WhiteSmoke", "White")
将其设置为组变量将不起作用,因为排序是在分组之后应用的(这意味着在生成值后重新排列行)。
Private m_s_count As ULong = 0
Public Function IncrementRunningValue() As ULong
m_s_count = m_s_count + 1UL
Return m_s_count - 1UL
End Function
Public Function GetRunningValue() As ULong
Return m_s_count
End Function
或者你可以做得更简单:
Private m_s_AlternatingColor1Count As ULong = 0
Private Function ComputeAlternatingColor1(val As ULong) As String
If val Mod 2 = 0 Then
Return "WhiteSmoke"
End If
Return "White"
End Function
Public Function IncrementAlternatingColor1() As String
m_s_AlternatingColor1Count = m_s_AlternatingColor1Count + 1UL
Dim alternatingColor As String = ComputeAlternatingColor1(m_s_AlternatingColor1Count)
Return alternatingColor
End Function
Public Function GetAlternatingColor1() As String
Return ComputeAlternatingColor1(m_s_AlternatingColor1Count)
End Function
然后在第一行的背景颜色:
=Code.IncrementAlternatingColor1()
以及所有后续行的背景颜色:
=Code.GetAlternatingColor1()
这样做的优点是您可以在一处切换颜色(DRY)。