Data Search

The ITabSearch interface is used to search the data.

The example of data search in regular report with the REPORT_TAB identifier is given. The report contains analytical data area. The search results are displayed in the console window.

Consider that the REPORT_TAB report has following analytical data area:

The console window displays following results:

The search of the 12 text is made by all table cells

    Address: found text

    F2: 12

    E3: 12

    D4: 12

    C5: 12

    B6: 12

Search the 1 text in the fourth table column

    Address: found text

    E0: 1998A1

    E1: 10

    E2: 11

    E3: 12

    E4: 13

    E5: 14

    E6: 15

Search the 0 text in the third table row

    Address: found text

    D2: 10

Fore Example

To execute the example, add links to the Metabase, Report, Tab assemblies.

// Search procedure
Sub Search;
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    CellSearch: ITabCellSearch;
    Result: ITabSearchResult;
    RowSearch: ITabRowSearch;
    ColumnSearch: ITabColumnSearch;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get regular report
    Report := mb.ItemById("REPORT_TAB").Bind As IPrxReport;
    // Get table
    Table := (Report.ActiveSheet As IPrxTable).TabSheet;
    // Create an object to search by all cells
    CellSearch := Table.CreateCellSearch;
    // Set data search range
    CellSearch.Range := Table.Regions.Item(0).Range;
    // Determine to not take into account case during the search
    CellSearch.CaseSensitive := False;
    // Determine search direction: by rows
    CellSearch.Direction := TabCellSearchDirection.Rows;
    // Determine that search is made by word part
    CellSearch.WholeWordsOnly := False;
    // Determine that search is made by cell text
    CellSearch.Target := TabCellSearchTarget.Text;
    // Set search text
    CellSearch.Text := "12";
    // Search
    Result := CellSearch.Execute;
    // Display results to the console window
    Debug.WriteLine("Search the 12 text by all table cells");
    PrintResult(Result);
    // Create an object to search by rows
    RowSearch := Table.CreateRowSearch;
    // Set search condition: search in the fourth column of  the 1 text part with case insensitivity
    RowSearch.AddCondition(4"1"FalseFalse);
    // Search
    Result := RowSearch.Execute;
    // Display results to the console window
    Debug.WriteLine("Search of the 1 text in the fourth table column");
    PrintResult(Result);
    // Create object to search by columns
    ColumnSearch := Table.CreateColumnSearch;
    // Set search condition: search in the third rowof a part of the 0 text with case insensivity
    ColumnSearch.AddCondition(3"0"FalseFalse);
    // Search
    Result := ColumnSearch.Execute;
    // Display results to the console window
    Debug.WriteLine("Search of the 0 text in the third row of the table");
    PrintResult(Result);
End Sub Search;

// Procedure to display search results
Sub PrintResult(Result: ITabSearchResult);
Var
    Range: ITabRange;
Begin
    If Result <> Null
    Then
        Debug.WriteLine("    Address: found text");
        Repeat
            Range := Result.Range;
            Debug.WriteLine("    " + Range.Address + ": " + Range.Text);
            If Not Result.Next Then
                Break;
            End If;
        Until False;
    Else
        Debug.WriteLine("    Text that satisfies search conditions is not found");
    End If;
End Sub PrintResult;

Fore.NET Example

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

// Search procedure 
Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    CellSearch: ITabCellSearch;
    Result: ITabSearchResult;
    RowSearch: ITabRowSearch;
    ColumnSearch: ITabColumnSearch;
Begin
    // Get current repository
    mb := Params.Metabase;
    // Get regular report
    Report := mb.ItemById["REPORT_TAB"].Bind() As IPrxReport;
    // Get table
    Table := (Report.ActiveSheet As IPrxTable).TabSheet;
    // Create an object to search by all cells
    CellSearch := Table.CreateCellSearch();
    // Set data search range
    CellSearch.Range := Table.Regions.Item[0].Range;
    // Determine to not take into account case during the search
    CellSearch.CaseSensitive := False;
    // Determine search direction: by rows
    CellSearch.Direction := TabCellSearchDirection.tcsdRows;
    // Determine that search is made by word part
    CellSearch.WholeWordsOnly := False;
    // Determine that search is made by cell text
    CellSearch.Target := TabCellSearchTarget.tcstText;
    // Set search text
    CellSearch.Text := "12";
    // Search
    Result := CellSearch.Execute();
    // Display results to the console window
    System.Diagnostics.Debug.WriteLine("Search of the 12 text by all table cells");
    PrintResult(Result);
    // Create an object to search by rows
    RowSearch := Table.CreateRowSearch();
    // Set search condition: search in the fourth column of  the 1 text part with case insensitivity
    RowSearch.AddCondition(4"1"FalseFalse);
    // Search
    Result := RowSearch.Execute();
    // Display results to the console window
    System.Diagnostics.Debug.WriteLine("Search of the 1 text in the fourth table column");
    PrintResult(Result);
    // Create object to search by columns
    ColumnSearch := Table.CreateColumnSearch();
    // Set search condition: search in the third rowof a part of the 0 text with case insensivity
    ColumnSearch.AddCondition(3"0"FalseFalse);
    // Search
    Result := ColumnSearch.Execute();
    // Display results to the console window
    System.Diagnostics.Debug.WriteLine("Search of the 0 text in the third table row");
    PrintResult(Result);
End Sub;

// Procedure to display search results
Public Shared Sub PrintResult(Result: ITabSearchResult);
Var
    Range: ITabRange;
Begin
    If Result <> Null
    Then
        System.Diagnostics.Debug.WriteLine("    Address: found text");
        Repeat
            Range := Result.Range;
            System.Diagnostics.Debug.WriteLine("    " + Range.Address + ": " + Range.Text);
            If Not Result.Next() Then
                Break;
            End If;
        Until False;
    Else
        System.Diagnostics.Debug.WriteLine("    Text that satisfies search conditions is not found");
    End If;
End Sub PrintResult;

See also:

General Programming Principles Using the Tab Assembly