Conditional Formatting Application

To set up data conditional formatting in the table, the ITabFormatConditions interface is used.

The example of conditional formatting setting in regular report with the REPORT_TAB identifier is given. The report contains analytical data area.

Cells containing the value that is bigger that average are selected. As a result the table looks as follows:

Example

Executing the example requires to add links to the Drawing, Metabase, Report, Tab system assemblies.

Sub CondFormat;
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    TabConds: ITabFormatConditions;
    FormatCond: ITabFormatCondition;
    Average: ITabFormatAverage;
    Style: ITabCellStyle;
    Color: IGxColor;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get regular report
    Report := mb.ItemById("REPORT_TAB").Edit As IPrxReport;
    // Get table
    Table := (Report.ActiveSheet As IPrxTable).TabSheet;
    // Get collection of conditional formatting conditions
    TabConds := Table.FormatConditions;
    // Clear condition collection
    TabConds.Clear;
    // Create new condition
    FormatCond := TabConds.Add;
    // Set a range for which the table style is used
    FormatCond.Range := Table.Regions.Item(0).Range;
    // Determine that condition is active
    FormatCond.Enabled := True;
    // Set condition type: cells with values greater or less than average
    FormatCond.Type := TabConditionType.Average;
    // Set up condition
    Average := FormatCond.Details As ITabFormatAverage;
    // Set condition: format cells with value greater than average
    Average.Type := TabFormatAverageType.Above;
    // Set formatting style of background of cells which respect the condition
    Style := New TabCellStyle.Create;
    Color := New GxColor.CreateRGB(98200255);
    Style.BackgroundColor := Color;
    Average.Style := Style;
    // Save changes
    (Report As IMetabaseObject).Save;
End Sub CondFormat;

See also:

General Programming Principles Using the Tab Assembly