在水晶报表中,如何动态设置渐变上的交叉表格式?

问题描述 投票:0回答:1

这已经在其他地方被问过,包括Crystal Reports Cross Tab Conditional Formatting,但是我发现很难找到这个问题的答案,而且还发现答案非常具体。

如何动态自动地设置 Crystal Reports 中交叉表中的单元格格式以显示任意两种颜色之间的渐变?

crystal-reports gradient conditional-formatting
1个回答
0
投票

我开发了一段通用代码,应该易于修改并应用于任何双色渐变比例。

在交叉表中选择要修改的单元格,然后选择“设置字段格式”。转到边框选项卡。单击背景旁边的 x+2 按钮。在公式字段中输入以下代码,然后保存。

local Numbervar max := 100; -- Put in the highest possible value here. I'm using percentages so this goes up to 100.

// Reference Yellow 255,231,63 -- Pick colour one here, for the low end of the scale. This is yellow. You'll need the RGB and plug them in below
local Numbervar c1r := 255; // red value for the first colour
local Numbervar c1g := 231; // green value for the first colour
local Numbervar c1b := 63; // blue value for the first colour

// Reference Green 105,192,98 -- Pick colour two here, for the high end of the scale. This is green.
local Numbervar c2r := 105; // red value for the second colour
local Numbervar c2g := 192; // green value for the second colour
local Numbervar c2b := 98; // blue value for the second colour

local Numbervar cRed;
local Numbervar cGreen;
local Numbervar cBlue;

if c1r = c2r then cRed := c1r
else if c1r > c2r then cRed := Floor(c2r + (c1r-c2r) * (1-currentfieldvalue/max))
else cRed := Floor(c1r + (c2r-c1r) * (currentfieldvalue/max));

if c1g = c2g then cGreen := c1g
else if c1g > c2g then cGreen := Floor(c2g + (c1g-c2g) * (1-currentfieldvalue/max))
else cGreen := Floor(c1g + (c2g-c1g) * (currentfieldvalue/max));

if c1b = c2b then cBlue := c1b
else if c1b > c2b then cBlue := Floor(c2b + (c1b-c2b) * (1-currentfieldvalue/max))
else cBlue := Floor(c1b + (c2b-c1b) * (currentfieldvalue/max));

color(cRed, cGreen, cBlue)
© www.soinside.com 2019 - 2024. All rights reserved.