基於多種條件對單元格進行著色我編寫了以下程式碼來根據條件為單元格著色。我需要再添加一個條件 -
如果重量在目標值的 -2% 範圍內,則需要將儲存格著色為黃色。我該如何操作?
dt << New Column("color cells",
Formula(If(:Target> :weight, :weight << color cells("Red", Row()); .,
:weight << color cells("Green", Row()); .)),
Hide(1)
);
謝謝
回覆:依多種條件為儲存格著色1. 如果您打算使用 JSL,您需要花時間閱讀腳本指南:幫助==>書籍==>腳本指南
2.以下是一個簡單的腳本,可以產生您所描述的顏色
Names Default To Here( 1 );
dt = Current Data Table();
colNamesList = dt << get column names( string );
For( theRow = 1, theRow <= N Rows( dt ), theRow++,
For( theCol = 2, theCol <= N Items( colNamesList ), theCol++,
If(
:Target[theRow] > Column( dt, colNamesList[theCol] )[theRow],
Column( dt, colNamesList[theCol] ) << color cells( "Red", theRow );
.;,
Column( dt, colNamesList[theCol] )[theRow] < :Target[theRow] + (.02 *
Abs( :Target[theRow] )) & Column( dt, colNamesList[theCol] )[theRow] >
:Target[theRow] - (.02 * Abs( :Target[theRow] )),
Column( dt, colNamesList[theCol] ) << color cells( "Yellow", theRow );
.;,
Column( dt, colNamesList[theCol] ) << color cells( "Green", theRow );
.;
)
)
);回覆:依多種條件為儲存格著色需要編寫此邏輯的變體腳本。 我有 4 列數據,需要將每個單元格中的值與目標值進行比較。 而且我事先也不知道列名。 這個怎麼做? 簡而言之,需要將 A、B、C 和 D 列中的值與目標列中的對應值以及相應的顏色代碼(綠色、黃色或紅色)進行比較。
| 目標 | A | 乙 | C | D |
| 99% | 1% | 8% | 93% | 10% |
| 52% | 55% | 62% | 22% | 19% |
| 39% | 89% | 18% | 33% | 25.50% |
| 16% | 11% | 92% | 10% | 2% |
回覆:依多種條件為儲存格著色如果(
:目標 > :重量,
:weight << 顏色儲存格( "紅色", Row() );
.;,
:權重 < :目標 + (.02 * Abs( :目標 )) & :權重 > :目標 - (.02 *
絕對值(:目標)),
:weight << 顏色儲存格( "黃色", Row() );
.;,
:weight << 顏色儲存格( "綠色", Row() );
.;
);