table lift ...

Prev Next

Function Names

table lift header row, table lift headers, table lift contents

Description

This function is particularly useful for imported tables where the headers are not necessarily be located in the top row but somewhere else. To make things worse, the headers of the imported tables may be located in different rows. These functions described here will first search for existence of specified headers and then take following actions:

table search header row Just return the row number where headers have been found. No manipulations done on the table.
table lift header row Delete all rows above the detected headers so the entire header row and all contents below move up to the top of the table.
table lift headers Move the headers to the 1st row. The original location of the headers become blank. Old contents in the 1st row will be overwritten. All other contents remain unchanged.
table lift contents Moves the headers as well as the affected columns underneath up. All other columns in the table remain unaffected.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-3 (min 2 required for 'table lift headers' and 'table lift contents')

Parameters

No.TypeDescription
1.
input
string Name of existing table

Opt. 2
input
table columns Existing columns

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Any number of header names and column numbers may be specified

Note:This 2nd function parameter is not required when using 'table lift header row' or 'table search header row'. In this case, following algorithm is applied to find the header row:

  • If a first row with all columns to full table width are not blank, than this is assumed a header row
  • Otherwise, the number of non-blank contents in every row is checked.
  • The first row with the largest number of non-blank contents is assumed as the heaer row.

Opt. 3
input
string Check header option

With this option, you can make the search more restrictive, so wrong arrangements located further up in the table will not be detected first. Checking option 1 affecting the table headers. Only one option can be chosen. See separate table on next page for more details.

Hint: The following terms behave similarly as in the function table check headers in order to qualify for matches. For example, the option "full match" expects that the header row contains all specified headers and not more in oder to consider them found. Otherwise, searching continues in the rows below until the criteria are met.

must exist The specified header names must exist
Specifeid column numbers must be within 0..n-1 or -n..-1.
unique Like must exist, but also checks that the specified column headers are unique in the table, i.e. they exist only once.
full match Like unique, however the table must not contain more (or less) headers than those specified to check. The ordering does not matter. It's like tolerating full number of white pins after a guess in the Master Mind game.
sequence Like unique, but listed parameters are in left-to-right sequence. The checked headers do not need to be adjacent.
strict sequence Like sequence but all headers must be adjacent, being next to each other from left to right
identical Combination of full match and strict sequence. The headers provided and table headers must be identical: Same header names in the same sequence. This corresponds to full number of black pins in the Master Mind game.

Default value: must exist

Return value

TypeDescription
numeral Row number where header row has been found

-1 is returned if no header row has been found

Examples

  table initialize( 2 tables,
  { { Created by,  Nick, Miller, "", Last Update, "31.12.2019" },
    { Tennis, Players, "", "", Squash, Players },
    {     Still a, "", "", "", Last Name, First Name, City },
    {     Draft, "", "", "", Weber, Abel, 'Wilkes-Barre' },
    { First Name, Last Name, City, and, Tanner, Berta, San Monica },
    { Jane, Dominique, The Bronx, "", Miller, Dominique, Trenton },
    { Jasmine, Nelsson, Francfort, "", Quinn, Alex, Denver },
    { Dominique, Miller, Trenton, "", Jansen, Patricia, Albany } } );


  echo("Original table:");
  table list( 2 tables );


  table copy table( 2 tables, table );
  echo("Show 'table lift headers(..., must exist)':" );
  echo("Note: It will recognize the headers in the right table.");
  echo("Note: Contents below headers are not moved up.");

  table lift headers( table, {First Name, Last Name, City} ); // 'must exist' is default
  table list( table );


  table copy table( 2 tables, table );
  echo("Show 'table lift header row(..., must exist)':" );
  echo("Note: It will recognize the headers in the right table. Entire rows below move up.");

  table lift header row( table, {First Name, Last Name, City} ); // 'must exist' is default
  table list( table );

  table copy table( 2 tables, table );
  echo("Show 'table lift header row(..., sequence)':" );
  echo("Note: It will recognize the headers in the left table because they have same sequence.");

  table lift header row( table, {First Name, Last Name, City}, sequence );
  table list( table );

  table copy table( 2 tables, table );
  echo("Following code puts both tables with headers to 1st row" );
  table lift contents( table, {First Name, Last Name, City}, sequence );
  table lift contents( table, {Last Name, First Name, City}, sequence );
  table list( table );

Output

Original table:
    0 : Created by | Nick      | Miller    |     | Last Update | 31.12.2019 |             
    1 : Tennis     | Players   |           |     | Squash      | Players    |             
    2 : Still a    |           |           |     | Last Name   | First Name | City        
    3 : Draft      |           |           |     | Weber       | Abel       | Wilkes-Barre
    4 : First Name | Last Name | City      | and | Tanner      | Berta      | San Monica  
    5 : Jane       | Dominique | The Bronx |     | Miller      | Dominique  | Trenton     
    6 : Jasmine    | Nelsson   | Francfort |     | Quinn       | Alex       | Denver      
    7 : Dominique  | Miller    | Trenton   |     | Jansen      | Patricia   | Albany      

Show 'table lift headers(..., must exist)':
Note: It will recognize the headers in the right table.
Note: Contents below headers are not moved up.
    0 : Created by | Nick      | Miller    |     | Last Name | First Name | City        
    1 : Tennis     | Players   |           |     | Squash    | Players    |             
    2 : Still a    |           |           |     |           |            |             
    3 : Draft      |           |           |     | Weber     | Abel       | Wilkes-Barre
    4 : First Name | Last Name | City      | and | Tanner    | Berta      | San Monica  
    5 : Jane       | Dominique | The Bronx |     | Miller    | Dominique  | Trenton     
    6 : Jasmine    | Nelsson   | Francfort |     | Quinn     | Alex       | Denver      
    7 : Dominique  | Miller    | Trenton   |     | Jansen    | Patricia   | Albany      

Show 'table lift header row(..., must exist)':
Note: It will recognize the headers in the right table. Entire rows below move up.
    0 : Still a    |           |           |     | Last Name | First Name | City        
    1 : Draft      |           |           |     | Weber     | Abel       | Wilkes-Barre
    2 : First Name | Last Name | City      | and | Tanner    | Berta      | San Monica  
    3 : Jane       | Dominique | The Bronx |     | Miller    | Dominique  | Trenton     
    4 : Jasmine    | Nelsson   | Francfort |     | Quinn     | Alex       | Denver      
    5 : Dominique  | Miller    | Trenton   |     | Jansen    | Patricia   | Albany      

Show 'table lift header row(..., sequence)':
Note: It will recognize the headers in the left table because they have same sequence.
    0 : First Name | Last Name | City      | and | Tanner | Berta     | San Monica
    1 : Jane       | Dominique | The Bronx |     | Miller | Dominique | Trenton   
    2 : Jasmine    | Nelsson   | Francfort |     | Quinn  | Alex      | Denver    
    3 : Dominique  | Miller    | Trenton   |     | Jansen | Patricia  | Albany    

Following code puts both tables with headers to 1st row
    0 : First Name | Last Name | City      |     | Last Name | First Name | City        
    1 : Jane       | Dominique | The Bronx |     | Weber     | Abel       | Wilkes-Barre
    2 : Jasmine    | Nelsson   | Francfort |     | Tanner    | Berta      | San Monica  
    3 : Dominique  | Miller    | Trenton   |     | Miller    | Dominique  | Trenton     
    4 :            |           |           | and | Quinn     | Alex       | Denver      
    5 :            |           |           |     | Jansen    | Patricia   | Albany      
    6 :            |           |           |     |           |            |             
    7 :            |           |           |     |           |            |             

Try it yourself: Open LIB_Function_table_lift_header_row.b4p in B4P_Examples.zip. Decompress before use.

See also

table search header row