table process cells (selected rows)

Prev Next

Function Names

table process cells, table process all cells, table process cells selected rows

Description

Slightly different from the the functions table process() and table process selected rows(), the specified statements are applied on every existing table cell (from left to right) and not only once per row. The statements for processing the data in every cell are provided as function parameters. For this function, the enabled partial table specifications also includes referencing the current column number by simply specifying a '.' (point) and you can use the function col() to retrieve the current column number.

table process all cells will also process all elements in row 0 (header row), too, whereas the other funnctions skip the header row.

This feature allows simple formulation of instructions without writinng a 2-dimensional loop. The closest relative of this function is the combination of for all table rows() and for all table columns() which describe two nested loops

Hint: If the table contains rows with different widths and you want to apply this function to the full table row width as provided in the header row or longest row, then use the function table fit() first in order to prepare the table to your needs.

Call as: procedure or function

Restrictions

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

Parameter count

2-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

Opt. 2.
code
expression
:string
Expression to select rows

Applicable to table process selected rows only:
Specify the conditions or rules to select the rows. See expressions to select rows. It will be calculated only once per row (and not for every cell).
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), ....

2. / 3.
code
statements
:string
Statements (applicable where rows are selected)

table process cells: The statements provided will be executed for every row.
table process cells selected rows: The statements provided will be executed for every row where the condition calculated before returned true.

The table context for partial table specifications is available for referencing just the columns easily. Example: [Full Name]=[First Name]+' '+[Last Name];.
Hint: If you encounter an error message at the very end of the program after you worked on a statement, you may proabably have forgotton to add the closing parentheses to close the function call.

4.
code
statements
:string
Statements (otherwise)

table process cells: Not applicable. This function accepts 3 parameters only. table process cells selected rows: The statements provided will be executed for every cell in every row where the condition calculated for that row returned false.

The table context for partial table specifications is available for referencing just the columns easily. Example: [Full Name]=[First Name]+' '+[Last Name];.
Hint: If you encounter an error message at the very end of the program after you worked on a statement, you may proabably have forgotton to add the closing parentheses to close the function call.

Return value

TypeDescription
numeral Number of cells processed

With table process selected rows, the number of selected rows (and processed with statements from 3rd function parameter) are counted.

Examples

  table initialize ( animals, { {Animal, Group, Special abilities},
      { parakeet, bird, can fly },  { moose, mammal },  { ape, mammal, quite samrt },  { sparrow, bird } , { trout, fish }, { bass, fish },
      { canary, bird }, { penguin, bird }, { beluga, mammal, submarine sonar} } );

  table process cells               ( animals, [.] += '!' );                      // Add an exclamation to text in every existing cell
  table process cells selected rows ( animals, [Group]=='mammal!', [.] = +[.] );  // Convert all contents (except header row) to upper case.

  table list ( animals );

Output

    0 : Animal    | Group   | Special abilities
    1 : parakeet! | bird!   | can fly!         
    2 : MOOSE!    | MAMMAL! |                  
    3 : APE!      | MAMMAL! | QUITE SAMRT!     
    4 : sparrow!  | bird!   |                  
    5 : trout!    | fish!   |                  
    6 : bass!     | fish!   |                  
    7 : canary!   | bird!   |                  
    8 : penguin!  | bird!   |                  
    9 : BELUGA!   | MAMMAL! | SUBMARINE SONAR!

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

See also

table process
table process selected rows
table process columns
table process selected columns
table process cells in columns
table process cells in columns selected rows
table manipulate