我有一份报告作为一张桌子。我想为每列设置一个随机的backgroundcolor。
为此,我创建了一个自定义脚本:
Public Function GetColor()
Dim intHighNumber AS Decimal = 255
Dim intLowNumber AS Decimal = 100
Dim NewColor AS String
Dim Red AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Green AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Blue AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
NewColor = "#" & Hex(Red) & Hex(Green) & Hex(Blue)
Return NewColor
End Function
在第一个单元格中,我将Fill Expression设置为:= code.GetColor() 直到这里它完美无缺,但现在我希望列的其余部分使用相同的颜色...所以我在表达式“= Fields!myField.BackgroundColor”中填写但是这不起作用...
我不知道如何解决这个问题......
非常感谢你的帮助: - )
答案 0 :(得分:0)
Private string _LastColorUser=""
Public Function LastColorUsed()
Return _LastColorUsed
End Function
Public Function GetColor()
Dim intHighNumber AS Decimal = 255
Dim intLowNumber AS Decimal = 100
Dim NewColor AS String
Dim Red AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Green AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Blue AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
NewColor = "#" & Hex(Red) & Hex(Green) & Hex(Blue)
_LastColorUser=NewColor;
Return NewColor
End Function
答案 1 :(得分:0)
你需要做的是记住列的颜色设置,这样你就可以在页眉,页脚等中重复使用它。我们可以通过一个数组实现这一点,该数组首次返回一个新颜色,并且颜色相同。索引,如果之前已分配该颜色。
以下是自定义代码:
Dim Colors(0 to 9) As String
Function GetColor(Color As Integer) As String
Dim intHighNumber AS Decimal = 255
Dim intLowNumber AS Decimal = 100
Dim ThisColor AS String
if (Colors(Color) <> "") Then
ThisColor = Colors(Color)
else
Dim Red AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Green AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Dim Blue AS Decimal = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
ThisColor = "#" & Hex(Red) & Hex(Green) & Hex(Blue)
Colors(Color) = ThisColor
End If
Return ThisColor
End Function
然后在您的单元格中,您只需调用GetColor
函数,传递您希望单元格具有的颜色索引号。例如,第一列的标题,详细信息和页脚单元格的BackgroundColor
属性表达式都是:
=Code.GetColor(0)
然后,您只需为每列使用不同的颜色索引。
确保您为数组标注了足够的空间来存储所有颜色(如果您想使用动态数组,每次添加新颜色时也可以ReDim
数组。)
答案 2 :(得分:0)
@Chris谢谢你,这就是我所需要的。 因为我的列是动态的,所以我必须编写另一个函数来获取数字:
Public Function GetColumnNumber(ByVal parameter as Parameter,ByVal SSID As String) as String
For i as integer = 0 to parameter.Count-1
If CStr(parameter.Value(i)) = SSID THEN
Return i
END IF
Next
End Function
在Cell中写道:
=code.GetColor(code.GetColumnNumber(Parameters!SSID,Fields!SSID.Value))
再次感谢:)