Mic*_*ren 142 sql-server formatting reporting-services
如何在SQL Server Reporting Services报告中对交替行进行着色?
Mic*_*ren 213
转到表行的BackgroundColor属性并选择"Expression ..."
使用此表达式:
= IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent")
Run Code Online (Sandbox Code Playgroud)
这个技巧可以应用于报告的许多方面.
在.NET 3.5+中您可以使用:
= If(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent")
Run Code Online (Sandbox Code Playgroud)
不寻找代表 - 我只是自己研究这个问题,并认为我会分享.
Cat*_*h22 88
使用IIF(RowNumber ...)可能会在行进行分组时导致一些问题,另一种方法是使用简单的VBScript函数来确定颜色.
这是一个更多的努力,但当基本解决方案不够时,它是一个不错的选择.
基本上,您将代码添加到报告中,如下所示......
Private bOddRow As Boolean
'*************************************************************************
' -- Display green-bar type color banding in detail rows
' -- Call from BackGroundColor property of all detail row textboxes
' -- Set Toggle True for first item, False for others.
'*************************************************************************
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
Run Code Online (Sandbox Code Playgroud)
然后在每个单元格上,按如下方式设置BackgroundColor:
=Code.AlternateColor("AliceBlue", "White", True)
Run Code Online (Sandbox Code Playgroud)
有关此Wrox文章的详细信息
小智 65
当我使用Catch22的解决方案时,我得到了国际象棋效果,我认为因为我的矩阵在设计中有不止一列.那个表达对我很好:
=iif(RunningValue(Fields![rowgroupfield].Value.ToString,CountDistinct,Nothing) Mod 2,"Gainsboro", "White")
Run Code Online (Sandbox Code Playgroud)
Mic*_*ins 20
我已经改变了@Catch22的解决方案有点因为我不喜欢进入每个领域的想法,如果我决定要改变其中一种颜色.这在需要更改颜色变量的众多字段的报告中尤为重要.
'*************************************************************************
' -- Display alternate color banding (defined below) in detail rows
' -- Call from BackgroundColor property of all detail row textboxes
'*************************************************************************
Function AlternateColor(Byval rowNumber as integer) As String
Dim OddColor As String = "Green"
Dim EvenColor As String = "White"
If rowNumber mod 2 = 0 then
Return EvenColor
Else
Return OddColor
End If
End Function
Run Code Online (Sandbox Code Playgroud)
注意到我已将功能从接受颜色的功能更改为包含要使用的颜色的功能.
然后在每个字段中添加:
=Code.AlternateColor(rownumber(nothing))
Run Code Online (Sandbox Code Playgroud)
这比手动更改每个字段的背景颜色中的颜色要强大得多.
Bes*_*ska 16
我注意到的一件事是前两种方法都没有任何关于第一行应该是什么颜色的概念; 该组将以与前一组的最后一行相反的颜色开始.我希望我的小组始终以相同的颜色开始......每组的第一行应始终为白色,下一行应为彩色.
基本概念是在每个组启动时重置切换,所以我添加了一些代码:
Private bOddRow As Boolean
'*************************************************************************
' -- Display green-bar type color banding in detail rows
' -- Call from BackGroundColor property of all detail row textboxes
' -- Set Toggle True for first item, False for others.
'*************************************************************************
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
'
Function RestartColor(ByVal OddColor As String) As String
bOddRow = True
Return OddColor
End Function
Run Code Online (Sandbox Code Playgroud)
所以我现在有三种不同的细胞背景:
这适合我.如果您希望分组行是非彩色的,或者是不同的颜色,那么从这个方面来看,如何更改它应该是相当明显的.
请随意添加关于可以采取哪些措施来改进此代码的评论:我对SSRS和VB都是全新的,所以我强烈怀疑还有很大的改进空间,但基本的想法看似合理(并且它很有用对我来说)所以我想把它扔出去.
小智 11
对于组页眉/页脚:
=iif(RunningValue(*group on field*,CountDistinct,"*parent group name*") Mod 2,"White","AliceBlue")
Run Code Online (Sandbox Code Playgroud)
您还可以使用它来"重置"每个组中的行颜色计数.我希望每个子组中的第一个细节行以White开头,这个解决方案(在详细行上使用时)允许这样做:
=IIF(RunningValue(Fields![Name].Value, CountDistinct, "NameOfPartnetGroup") Mod 2, "White", "Wheat")
Run Code Online (Sandbox Code Playgroud)
请参阅:http://msdn.microsoft.com/en-us/library/ms159136(v = sql.100).aspx
Michael Haren的解决方案对我来说很好.但是我收到一条警告说"透明"在预览时不是有效的BackgroundColor.通过在SSRS中设置Report Element的BackgroundColor,找到了一个快速修复程序 .使用Nothing而不是"Transparent"
= IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", Nothing)
Run Code Online (Sandbox Code Playgroud)
在不使用VB的情况下解决此问题的唯一有效方法是在行分组(以及列分组外)中"存储"行分组模数值,并在列分组中明确引用它.我找到了这个解决方案
http://ankeet1.blogspot.com/2009/02/alternating-row-background-color-for.html
但Ankeet并不是解释正在发生的事情的最佳工作,他的解决方案建议在常量值上创建分组的不必要步骤,所以这是我对具有单个行组RowGroup1的矩阵的逐步过程:
将RowGroupColor的文本框的值设置为
=iif(RunningValue(Fields![RowGroupField].Value
,CountDistinct,Nothing) Mod 2, "LightSteelBlue", "White")
将所有行单元格的BackgroundColor属性设置为
"=ReportItems!RowGroupColor.Value"
瞧!这也解决了这个线程中提到的很多问题:
如果SSRS会暴露除Textboxes上的Value之外的属性,那将是很棒的.您可以在行组文本框的BackgroundColor属性中填充此类计算,然后在所有其他单元格中将其作为ReportItems!RowGroup.BackgroundColor引用.
啊,我们可以梦想......
我的问题是我希望连续的所有列都具有相同的背景.我按行和按列分组,在这里我用前两个解决方案得到了第1列中的所有行,带有彩色背景,第2列中的所有行都带有白色背景,第3列中的所有行都带有彩色背景, 等等.这是因为如果RowNumber和bOddRow(的Catch22的解决方案)要注意我的栏目组,而不是忽略了,只用一个新行交替.
我想要的是第1行中的所有列都有白色背景,然后第2行中的所有列都有彩色背景,然后第3行中的所有列都有白色背景,依此类推.我通过使用选定的答案得到了这个效果,但不是传递Nothing给RowNumber我,我传递了我的列组的名称,例如
=IIf(RowNumber("MyColumnGroupName") Mod 2 = 0, "AliceBlue", "Transparent")
Run Code Online (Sandbox Code Playgroud)
认为这可能对其他人有用.
| 归档时间: |
|
| 查看次数: |
272033 次 |
| 最近记录: |