【问题标题】:Crystal Reports Cross Tab Conditional FormattingCrystal Reports 交叉表条件格式
【发布时间】:2012-10-08 23:35:16
【问题描述】:

我想实现类似于 Excel 中的“色阶”功能的简化结果,即基于最小值(红色)到最大值(绿色)的渐变着色,但在我使用 Crystal Reports 2008 的交叉表中除外。我的交叉表看起来有点像这样:

 HOURS    L1   L2  L3   L4  Total
 1 hours | 5 | 0 | 1 | 16 | 22 |
 2 hours | 0 | 1 | 0 | 10 | 11 |
 3 hours | 8 | 2 | 6 | 12 | 28 |
 TOTAL   |13 | 3 | 7 | 38 | 61 |

我的函数的原理是在交叉表中找到最大值,然后使用 20%、40%、60%、80% 的值来为背景着色。功能如下(格式>背景部分):

    if currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.2) then color(255,0,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.2) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.4)) then color(255,192,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.4) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.6)) then color(255,255,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.6) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.8)) then color(146,208,80)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.8)) then color(0,176,80)

它不优雅,也不能正常工作,任何帮助/建议将不胜感激。我没想到它会如此复杂,因为我最初假设它会起作用,但它告诉我“CurrentFieldValue”不是一个字段。

if CurrentFieldValue < ((Maximum (CurrentFieldValue))*0.2) then color(255,0,0)
else if ... etc.

【问题讨论】:

    标签: crystal-reports


    【解决方案1】:

    在这篇文章的一些帮助下:For each crosstab column, highlight maximum value,我设法得到了我想要的结果。希望这对其他人有帮助。干杯。

    local Numbervar max:=0;
    local Numbervar col;
    local Numbervar row;
    
    for col := 0 to GetNumColumns-2 do 
    (
        for row := 0 to GetNumRows-2 do 
        (
            local numbervar value := GridValueAt (row, col, CurrentSummaryIndex);
            if value > max 
                then max := value;
        );
    );
    
    ToText(max,"#");
    
    // Reference Red 248,105,107
    // ReferenceGreen 99,190,132
    
    local Numbervar cRed;
    local Numbervar cGreen;
    local Numbervar cBlue;
    
    cRed := Floor(99 + 149 * (1-(GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max)));
    
    cGreen := Floor(105 + 85 * (if (((GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max))*10) > 1 then 1));
    
    cBlue := Floor(107 + 25 * ((GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max)));
    
    color(cRed, cGreen, cBlue)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      相关资源
      最近更新 更多