table insert cells selected rows

Prev Next

Function Names

table insert cells selected rows

Description

This function inserts cells starting at a specified column in selected rows. The contents to the right will shift to the right accordingly.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters

Parameter count

3-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

2.
code
expression
:string
Expression to select rows

Specify the conditions or rules to select the rows. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

3.
input
table column Existing column

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

  • Only 1 header name or column number may be specified.

Opt. 4.
input
string Count

Number of cells to insert (with contents to the right shifting to the left accordingly)
Negative indexing is supported, i.e. -1 removes all cells till end of row (prior to inserting), -2 removes all cells except last column (which will left-shift accordingly), etc. The position of the last column relates to the last column of the widest row in the table, and not the header row or current row alone.

Default value: 1

Return value

TypeDescription
numeral Number of rows processed

Counts all rows selected where cells have been inserted.

Examples

       table initialize ( t,
         { { Nr,  A,  B,  C,  D,  E  },
                       {  1,  A1, B1, C1, D1, E1, F1, G1 },
                       {  2,  A2, B2, C2, D2, E2, F2, G2 },
                       {  3,  A3, B3, C3, D3, E3 },
                       {  4,  A4, B4, C4, D4, E4, F4, G4 },
                       {  5,  A5, B5, C5, D5, E5, F5, G5 } } );

       table copy table( t, u );

       echo("2 cells inserted in rows 2-4");
       a[] = table insert cells selected rows( t, ([Nr]=2..4), C, 2, ".." );
       table list ( t );
       echo("Number of rows affected: ", a[]);

       echo("Additional insertions till right side of table");
       a[] = table insert cells selected rows( u, ([Nr]=1,3), B, -1, "--" );
       table list ( u );
       echo("Number of rows affected: ", a[]);

Output

2 cells inserted in rows 2-4
    0 : Nr | A  | B  | C  | D  | E  |    |    |    |   
    1 : 1  | A1 | B1 | C1 | D1 | E1 | F1 | G1 |    |   
    2 : 2  | A2 | B2 | .. | .. | C2 | D2 | E2 | F2 | G2
    3 : 3  | A3 | B3 | .. | .. | C3 | D3 | E3 |    |   
    4 : 4  | A4 | B4 | .. | .. | C4 | D4 | E4 | F4 | G4
    5 : 5  | A5 | B5 | C5 | D5 | E5 | F5 | G5 |    |   

Number of rows affected: 3
Additional insertions till right side of table
    0 : Nr | A  | B  | C  | D  | E  |    |    |    |    |    |    |    |   
    1 : 1  | A1 | -- | -- | -- | -- | -- | -- | B1 | C1 | D1 | E1 | F1 | G1
    2 : 2  | A2 | B2 | C2 | D2 | E2 | F2 | G2 |    |    |    |    |    |   
    3 : 3  | A3 | -- | -- | -- | -- | -- | -- | B3 | C3 | D3 | E3 |    |   
    4 : 4  | A4 | B4 | C4 | D4 | E4 | F4 | G4 |    |    |    |    |    |   
    5 : 5  | A5 | B5 | C5 | D5 | E5 | F5 | G5 |    |    |    |    |    |   

Number of rows affected: 2
Try it yourself: Open LIB_Function_table_insert_cells_selected_rows.b4p in B4P_Examples.zip. Decompress before use.

See also

table insert cells in columns
table delete cells selected row