Crystal Reports for Rational Application Developer 設計工具指南

條件式格式化函式 (Crystal 語法)

如果要撰寫條件格式化函式,請以滑鼠右鍵按一下公式會影響的報表區域或欄位,按一下 [條件公式]。選取條件,在 [公式] 頁面上輸入條件公式。例如,您可以設定 {客戶.去年業績} 這個欄位的格式,超過 $100,000 的銷售量用綠色印出,低於 $15,000 的銷售量用紅色印出,其他的銷售量則用黑色印出。
範例
//Conditional formatting example 1
If {Customer.Last Year's Sales} > 100000 Then
crGreen
Else If {Customer.Last Year's Sales} < 15000 Then
crRed
Else
crBlack
這是字型色彩格式化函式,[色彩常數] 清單會出現在 [公式] 頁面的註解清單上。這個範例使用到三種函式:crGreen、crRed 及 crBlack。您也可以改用色彩常數的實際數值。例如,crRed 是 255,crGreen 是 32768。不過,使用色彩常數會使得公式更容易理解。Crystal 語法中的所有常數函式都具有 cr 這個前置字元。
Crystal 語法仍然支援前一版沒有 cr 前置字元的常數函式。例如,您可以使用 Red 來代替 crRed。但是,使用 cr 前置字元可以使常數函式具有組織,是較為建議的用法。

附註: 有些格式化屬性並不使用常數函式。例如,如果您不要印出銷售量低於 $50,000 的 {客戶.去年業績} 值,可以撰寫以下條件格式化公式來抑制顯示屬性:
//Conditional formatting example 2
If {Customer.Last Year's Sales} < 50000 Then
True //suppress the value
Else
False //do not suppress the value
或用更簡單的方法:
//Conditional formatting example 3 -
//equivalent to example 2
{Customer.Last Year's Sales} < 50000
如果去年業績低於 $50,000,則運算式
{Customer.Last Year's Sales} < 50000
為 True,公式也會傳回 True。相反地,如果去年業績高於或等於 $50,000,那麼
{Customer.Last Year's Sales} < 50000
為 False,公式也會傳回 False。



Business Objects, SAP 子公司
http://www.taiwan.businessobjects.com/
支援服務
http://www.taiwan.businessobjects.com/support/
產品說明文件網站
http://support.businessobjects.com/documentation/