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:

Fore Example

To execute the example, 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;

Fore.NET Example

Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Tab;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    TabConds: ITabFormatConditions;
    FormatCond: ITabFormatCondition;
    Average: ITabFormatAverage;
    Style: TabCellStyle;
    Color: GxColor;
Begin
    // Get current repository
    mb := Params.Metabase;
    // 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.tctAverage;
    // Set up condition
    Average := FormatCond.Details As ITabFormatAverage;
    // Set condition: format cells with value greater than average
    Average.Type := TabFormatAverageType.tfatAbove;
    // Set formatting style of background of cells which respect the condition
    Style := New TabCellStyle.Create();
    Color := New GxColorClass_2.Create();
    Color.CreateRGB(98200255);
    Style.BackgroundColor := Color;
    Average.Style := Style;
    // Save changes
    (Report As IMetabaseObject).Save();
End Sub;

See also:

General Programming Principles Using the Tab Assembly